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>
using namespace std;
#define int long long
const int mod = 1e9 + 7;
map<pair<int, int>, int> dp;
int n, k;
int calc(int i, int j) {
if (i < j || j == 0)
return 0;
else if (dp[{i, j}])
return dp[{i, j}];
else if (j > i - j + 1)
return calc(i, i - j + 1);
else if (i == j)
return dp[{i, j}] = 1;
return dp[{i, j}] = (j * calc(i - 1, j) + (i - j + 1) * calc(i - 1, j - 1)) % mod;
}
void solveTestCase() {
cin >> n >> k;
cout << calc(n, k);
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int test = 1;
// cin >> test;
for (int i = 1; i <= test; i++)
solveTestCase();
}
# | 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... |