This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define pp pop_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define rep(a, b, c) for (int a = (b); (a) <= (c); ++a)
#define per(a, b, c) for (int a = (b); (a) >= (c); --a)
#define nl '\n'
#define ioi exit(0);
using namespace std;
typedef long long ll;
const int MAX_N = (int)3e3 + 7;
const int mod = (int)1e9 + 7;
int n, k;
int dp[MAX_N][MAX_N];
int calc(int v = 2, int cnt = 1) {
if (v > n) return cnt == k;
if (~dp[v][cnt]) return dp[v][cnt];
return dp[v][cnt] = ((calc(v + 1, cnt) * 1ll * cnt % mod) + (calc(v + 1, cnt + 1) * 1ll * (v - cnt) % mod)) % mod;
}
int main() {
#ifdef IOI
freopen ("in.txt", "r", stdin);
#endif
cin >> n >> k;
memset(dp, -1, sizeof(dp));
cout << calc();
ioi
}
# | 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... |