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 pb emplace_back
#define AI(i) begin(i), end(i)
using namespace std;
using ll = long long;
template<class T> bool chmin(T &a, T b) { return b < a && (a = b, true); }
template<class T> bool chmax(T &a, T b) { return a < b && (a = b, true); }
#ifdef KEV
#define DE(args...) kout("[ " + string(#args) + " ] = ", args)
void kout() {cerr << endl;}
template<class T, class ...U> void kout (T v, U ...e) { cerr << v << ' ', kout(e...); }
template<class T> void debug(T L, T R) { while (L != R) cerr << *L << " \n"[next(L)==R], ++L; }
#else
#define DE(...) 0
#define debug(...) 0
#endif
// What I should check
// 1. overflow
// 2. corner cases
// Enjoy the problem instead of hurrying to AC
// Good luck !
const int MAX_N = 3010, p = 1e9 + 7;
ll dp[MAX_N][MAX_N];
void add(ll &a, ll b) { a += b - p, a += (a >> 63) & p; }
int32_t main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int n, k;
cin >> n >> k;
if (n >= MAX_N) return 1;
dp[1][0] = 1;
for (int i = 2;i <= n;++i) {
for (int j = 0;j < i;++j)
dp[i][j] = (dp[i-1][j] * (j + 1) +
(j ? dp[i-1][j-1] : 0) * (i - j)) % p;
// for (int j = 0;j < i;++j) {
// dp[i + 1][j] += dp[i][j] * (j + 1);
// dp[i + 1][j + 1] += dp[i][j] * (i - j);
// }
//
// add(dp[i + 1][j], dp[i][j] * (j + 1) % p);
// add(dp[i + 1][j + 1], dp[i][j] * (i + 1 - (j + 1)) % p);
}
cout << dp[n][k-1] << '\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... |