#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcount
#define ll long long
#define mp make_pair
#define f first
#define s second
const int N = 3001, MOD = 1000 * 1000 * 1000 + 7;
int n, k, dp[N][N];
void add(int &a, int b) {
a += b; a %= MOD;
}
signed main() {
#ifdef HOME
freopen("input.txt", "r", stdin);
#else
ios_base::sync_with_stdio(0); cin.tie(0);
#endif
cin >> n >> k;
--k;
dp[1][0] = 1;
for (int i = 1; i < n; ++i) {
for (int j = 0; j <= k; ++j) {
add(dp[i + 1][j], dp[i][j] * (j + 1));
add(dp[i + 1][j + 1], dp[i][j] * (i - j));
}
}
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 |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
380 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 |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
380 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 |
3 ms |
1528 KB |
Output is correct |
13 |
Correct |
4 ms |
1528 KB |
Output is correct |
14 |
Correct |
4 ms |
1784 KB |
Output is correct |
15 |
Correct |
4 ms |
2168 KB |
Output is correct |
16 |
Correct |
5 ms |
2296 KB |
Output is correct |
17 |
Correct |
3 ms |
1144 KB |
Output is correct |
18 |
Correct |
4 ms |
1656 KB |
Output is correct |
19 |
Correct |
3 ms |
1016 KB |
Output is correct |
20 |
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 |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
380 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 |
3 ms |
1528 KB |
Output is correct |
13 |
Correct |
4 ms |
1528 KB |
Output is correct |
14 |
Correct |
4 ms |
1784 KB |
Output is correct |
15 |
Correct |
4 ms |
2168 KB |
Output is correct |
16 |
Correct |
5 ms |
2296 KB |
Output is correct |
17 |
Correct |
3 ms |
1144 KB |
Output is correct |
18 |
Correct |
4 ms |
1656 KB |
Output is correct |
19 |
Correct |
3 ms |
1016 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
7 ms |
4348 KB |
Output is correct |
22 |
Correct |
7 ms |
4344 KB |
Output is correct |
23 |
Correct |
13 ms |
7928 KB |
Output is correct |
24 |
Correct |
14 ms |
8312 KB |
Output is correct |
25 |
Correct |
20 ms |
11768 KB |
Output is correct |
26 |
Correct |
20 ms |
12152 KB |
Output is correct |
27 |
Correct |
21 ms |
12152 KB |
Output is correct |
28 |
Correct |
9 ms |
5368 KB |
Output is correct |
29 |
Correct |
3 ms |
1400 KB |
Output is correct |
30 |
Correct |
20 ms |
12024 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 |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
380 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 |
3 ms |
1528 KB |
Output is correct |
13 |
Correct |
4 ms |
1528 KB |
Output is correct |
14 |
Correct |
4 ms |
1784 KB |
Output is correct |
15 |
Correct |
4 ms |
2168 KB |
Output is correct |
16 |
Correct |
5 ms |
2296 KB |
Output is correct |
17 |
Correct |
3 ms |
1144 KB |
Output is correct |
18 |
Correct |
4 ms |
1656 KB |
Output is correct |
19 |
Correct |
3 ms |
1016 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
7 ms |
4348 KB |
Output is correct |
22 |
Correct |
7 ms |
4344 KB |
Output is correct |
23 |
Correct |
13 ms |
7928 KB |
Output is correct |
24 |
Correct |
14 ms |
8312 KB |
Output is correct |
25 |
Correct |
20 ms |
11768 KB |
Output is correct |
26 |
Correct |
20 ms |
12152 KB |
Output is correct |
27 |
Correct |
21 ms |
12152 KB |
Output is correct |
28 |
Correct |
9 ms |
5368 KB |
Output is correct |
29 |
Correct |
3 ms |
1400 KB |
Output is correct |
30 |
Correct |
20 ms |
12024 KB |
Output is correct |
31 |
Runtime error |
59 ms |
24952 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
32 |
Halted |
0 ms |
0 KB |
- |