#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int N = 3007;
const int md = 1e9 + 7;
void add(int &a, int b) {
a += b;
if (a >= md) a -= md;
}
int sub(int a, int b) {
a -= b;
if (a < 0) a += md;
return a;
}
int mul(int a, int b) {
return ((ll)a * b) % md;
}
int dp[N][N];
int main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.setf(ios::fixed); cout.precision(20);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int n, k;
cin >> n >> k;
dp[1][1] = 1;
for (int i = 2; i <= n; ++i) {
for (int j = 1; j <= i; ++j) {
add(dp[i][j], mul(dp[i - 1][j], j));
add(dp[i][j], mul(dp[i - 1][j - 1], i - j + 1));
}
}
cout << dp[n][k] << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
3 ms |
760 KB |
Output is correct |
12 |
Correct |
4 ms |
1784 KB |
Output is correct |
13 |
Correct |
4 ms |
1784 KB |
Output is correct |
14 |
Correct |
4 ms |
1756 KB |
Output is correct |
15 |
Correct |
4 ms |
1784 KB |
Output is correct |
16 |
Correct |
4 ms |
1788 KB |
Output is correct |
17 |
Correct |
3 ms |
1272 KB |
Output is correct |
18 |
Correct |
4 ms |
1528 KB |
Output is correct |
19 |
Correct |
3 ms |
1016 KB |
Output is correct |
20 |
Correct |
4 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
3 ms |
760 KB |
Output is correct |
12 |
Correct |
4 ms |
1784 KB |
Output is correct |
13 |
Correct |
4 ms |
1784 KB |
Output is correct |
14 |
Correct |
4 ms |
1756 KB |
Output is correct |
15 |
Correct |
4 ms |
1784 KB |
Output is correct |
16 |
Correct |
4 ms |
1788 KB |
Output is correct |
17 |
Correct |
3 ms |
1272 KB |
Output is correct |
18 |
Correct |
4 ms |
1528 KB |
Output is correct |
19 |
Correct |
3 ms |
1016 KB |
Output is correct |
20 |
Correct |
4 ms |
504 KB |
Output is correct |
21 |
Correct |
11 ms |
6392 KB |
Output is correct |
22 |
Correct |
12 ms |
6392 KB |
Output is correct |
23 |
Correct |
11 ms |
6392 KB |
Output is correct |
24 |
Correct |
12 ms |
6440 KB |
Output is correct |
25 |
Correct |
12 ms |
6392 KB |
Output is correct |
26 |
Correct |
12 ms |
6392 KB |
Output is correct |
27 |
Correct |
12 ms |
6392 KB |
Output is correct |
28 |
Correct |
7 ms |
3576 KB |
Output is correct |
29 |
Correct |
4 ms |
1272 KB |
Output is correct |
30 |
Correct |
11 ms |
6392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
3 ms |
760 KB |
Output is correct |
12 |
Correct |
4 ms |
1784 KB |
Output is correct |
13 |
Correct |
4 ms |
1784 KB |
Output is correct |
14 |
Correct |
4 ms |
1756 KB |
Output is correct |
15 |
Correct |
4 ms |
1784 KB |
Output is correct |
16 |
Correct |
4 ms |
1788 KB |
Output is correct |
17 |
Correct |
3 ms |
1272 KB |
Output is correct |
18 |
Correct |
4 ms |
1528 KB |
Output is correct |
19 |
Correct |
3 ms |
1016 KB |
Output is correct |
20 |
Correct |
4 ms |
504 KB |
Output is correct |
21 |
Correct |
11 ms |
6392 KB |
Output is correct |
22 |
Correct |
12 ms |
6392 KB |
Output is correct |
23 |
Correct |
11 ms |
6392 KB |
Output is correct |
24 |
Correct |
12 ms |
6440 KB |
Output is correct |
25 |
Correct |
12 ms |
6392 KB |
Output is correct |
26 |
Correct |
12 ms |
6392 KB |
Output is correct |
27 |
Correct |
12 ms |
6392 KB |
Output is correct |
28 |
Correct |
7 ms |
3576 KB |
Output is correct |
29 |
Correct |
4 ms |
1272 KB |
Output is correct |
30 |
Correct |
11 ms |
6392 KB |
Output is correct |
31 |
Runtime error |
108 ms |
56952 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
32 |
Halted |
0 ms |
0 KB |
- |