#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;
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--;
vi dp(n+1,0),dp2(n+1,0);
dp[0] = dp2[0] = 1;
for (int i = 1;i<=n;i++) {
for (int j = 1;j<=i && j <= k;j++) {
dp[j] = add(mult(dp2[j],j+1),mult(dp2[j-1],i-j));
}
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... |