This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// dp[i][j] -> dp[i+1][j] * j
// dp[i][j] -> dp[i+1][j+1] * (i-j+1);
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 1e9 + 7;
int dp[3002][3002];
int n, k;
int32_t main() {
int n, k;
cin >> n >> k;
dp[0][0] = 1;
for (int i = 0; i <= n; i++) for (int j = 0; j <= k; j++) {
dp[i+1][j] += dp[i][j] * j % mod;
dp[i+1][j] %= mod;
dp[i+1][j+1] += dp[i][j] * (i-j+1) % mod;
dp[i+1][j+1] %= mod;
}
cout << dp[n][k] << '\n';
}
# | 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... |