#include <bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define vi vector<int>
#define ff first
#define ss second
#define sp << " " <<
#define all(x) x.begin(),x.end()
#define big(x) ((int)(x.size()))
using namespace std;
const int MOD = 1e9+7, LIM = 1e6+1, inf = 2e9;
const int N = 1e5+1;
int add(int x,int y) {
    if ((x + y) >= MOD) return x + y - MOD;
    return x + y;
}
int mult(int x,int y) {
    return (1LL * x * y) % MOD;
}
int expo(int x,int y) {
    if (!y) return 1;
    int e = expo(x, y >> 1);
    e = mult(e, e);
    if (y & 1) e = mult(e, x);
    return e;
}
void solve() {
    int n,k;
    cin >> n >> k;
    k--;
    int dp[n+1][n+1]{};
    dp[0][0] = 1;
    for (int i = 0;i<=n;i++) {
        for (int j = 0;j<=i;j++) {
            if (i == n) continue;
            dp[i+1][j] = add(dp[i+1][j],mult(dp[i][j],j+1));
            dp[i+1][j+1] = add(dp[i+1][j+1],mult(dp[i][j],i-j));
        }
    }
    cout << dp[n][k] << '\n';
}   
signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    #ifdef Dodi
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    #endif
    int t = 1;
    //cin >> t;
    while (t --> 0) solve();
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |