#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
typedef long long ll;
using namespace std;
const int maxn = 3005, mod = 1e9 + 7;
int dp[maxn][maxn];
int mul(const int& a, const int& b) { return (a * 1ll * b) % (ll)mod; }
void upd(int& a, const int& b) { a = (a + b) % mod; }
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int N, K;
cin >> N >> K;
dp[1][1] = 1;
for (int n = 2; n <= N; n++) for (int k = 1; k <= min(K, n); k++)
{
upd(dp[n][k], mul(dp[n - 1][k], k)); // umiestnime ho na koniec jedneho z k usekov
upd(dp[n][k], mul(dp[n - 1][k - 1], n - k + 1)); // umiestnime ho inde a vytvorime novy usek
}
cout << dp[N][K] << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
324 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
324 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
716 KB |
Output is correct |
12 |
Correct |
1 ms |
1484 KB |
Output is correct |
13 |
Correct |
1 ms |
1484 KB |
Output is correct |
14 |
Correct |
2 ms |
1612 KB |
Output is correct |
15 |
Correct |
2 ms |
1612 KB |
Output is correct |
16 |
Correct |
2 ms |
1612 KB |
Output is correct |
17 |
Correct |
1 ms |
1100 KB |
Output is correct |
18 |
Correct |
1 ms |
1356 KB |
Output is correct |
19 |
Correct |
1 ms |
844 KB |
Output is correct |
20 |
Correct |
1 ms |
320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
324 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
716 KB |
Output is correct |
12 |
Correct |
1 ms |
1484 KB |
Output is correct |
13 |
Correct |
1 ms |
1484 KB |
Output is correct |
14 |
Correct |
2 ms |
1612 KB |
Output is correct |
15 |
Correct |
2 ms |
1612 KB |
Output is correct |
16 |
Correct |
2 ms |
1612 KB |
Output is correct |
17 |
Correct |
1 ms |
1100 KB |
Output is correct |
18 |
Correct |
1 ms |
1356 KB |
Output is correct |
19 |
Correct |
1 ms |
844 KB |
Output is correct |
20 |
Correct |
1 ms |
320 KB |
Output is correct |
21 |
Correct |
3 ms |
4300 KB |
Output is correct |
22 |
Correct |
3 ms |
4300 KB |
Output is correct |
23 |
Correct |
6 ms |
5708 KB |
Output is correct |
24 |
Correct |
7 ms |
5708 KB |
Output is correct |
25 |
Correct |
9 ms |
6220 KB |
Output is correct |
26 |
Correct |
8 ms |
6300 KB |
Output is correct |
27 |
Correct |
9 ms |
6220 KB |
Output is correct |
28 |
Correct |
4 ms |
3404 KB |
Output is correct |
29 |
Correct |
1 ms |
1100 KB |
Output is correct |
30 |
Correct |
8 ms |
6220 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
324 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
716 KB |
Output is correct |
12 |
Correct |
1 ms |
1484 KB |
Output is correct |
13 |
Correct |
1 ms |
1484 KB |
Output is correct |
14 |
Correct |
2 ms |
1612 KB |
Output is correct |
15 |
Correct |
2 ms |
1612 KB |
Output is correct |
16 |
Correct |
2 ms |
1612 KB |
Output is correct |
17 |
Correct |
1 ms |
1100 KB |
Output is correct |
18 |
Correct |
1 ms |
1356 KB |
Output is correct |
19 |
Correct |
1 ms |
844 KB |
Output is correct |
20 |
Correct |
1 ms |
320 KB |
Output is correct |
21 |
Correct |
3 ms |
4300 KB |
Output is correct |
22 |
Correct |
3 ms |
4300 KB |
Output is correct |
23 |
Correct |
6 ms |
5708 KB |
Output is correct |
24 |
Correct |
7 ms |
5708 KB |
Output is correct |
25 |
Correct |
9 ms |
6220 KB |
Output is correct |
26 |
Correct |
8 ms |
6300 KB |
Output is correct |
27 |
Correct |
9 ms |
6220 KB |
Output is correct |
28 |
Correct |
4 ms |
3404 KB |
Output is correct |
29 |
Correct |
1 ms |
1100 KB |
Output is correct |
30 |
Correct |
8 ms |
6220 KB |
Output is correct |
31 |
Runtime error |
46 ms |
24964 KB |
Execution killed with signal 11 |
32 |
Halted |
0 ms |
0 KB |
- |