#include <bits/stdc++.h>
#pragma GCC optimize("O3,Ofast,unroll-loops")
#pragma GCC target("avx2")
#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;
void solve() {
    int n,k;
    cin >> n >> k;
    vi dp(n+1,0),dp2(n+1,0);
    dp2[1] = 1;
    for (int i = 1;i<=n;i++) {
        for (int j = 1;j<=i+1;j++) {
            dp[j] = (dp2[j]*j+dp2[j-1]*(i-j+1))%MOD;
            //cout << dp[j] << ' ';
        }
        //cout << '\n';
        dp.swap(dp2);
    }
    cout << dp2[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... |