#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#define pb push_back
#define F first
#define S second
#define ld long double
#define all(a) a.begin(),a.end()
#define pii pair <int,int>
#define int long long
#define PII pair<pii , pii>
#define sz(v) (int)v.size()
#define rep(i , a , b) for(int i=a;i <= (b);i++)
#define per(i , a , b) for(int i=a;i >= (b);i--)
#define deb(x) cout <<#x << " : " << x << "\n" ;
using namespace std ;
const int maxn = 3002 , mod = 1e9 + 7 , b = 56 , maxp = 15e5 + 10, inf= 1e9+10 , lg = 20;
int dp[maxn][maxn];
signed main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n , k ;
cin >> n >> k ;
dp[1][0] = 1;
rep(i , 1 , n){
rep(j , 0, k){
dp[i+1][j] = (dp[i][j]*(j+1) + dp[i+1][j])%mod ;
dp[i+1][j+1] = (dp[i][j] * (i-j) + dp[i+1][j+1])%mod ;
}
}
cout << dp[n][k-1] << '\n';
}
/*
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
860 KB |
Output is correct |
12 |
Correct |
1 ms |
1628 KB |
Output is correct |
13 |
Correct |
1 ms |
1624 KB |
Output is correct |
14 |
Correct |
1 ms |
1884 KB |
Output is correct |
15 |
Correct |
1 ms |
2140 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
1116 KB |
Output is correct |
18 |
Correct |
1 ms |
1628 KB |
Output is correct |
19 |
Correct |
1 ms |
1116 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
860 KB |
Output is correct |
12 |
Correct |
1 ms |
1628 KB |
Output is correct |
13 |
Correct |
1 ms |
1624 KB |
Output is correct |
14 |
Correct |
1 ms |
1884 KB |
Output is correct |
15 |
Correct |
1 ms |
2140 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
1116 KB |
Output is correct |
18 |
Correct |
1 ms |
1628 KB |
Output is correct |
19 |
Correct |
1 ms |
1116 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
3 ms |
4444 KB |
Output is correct |
22 |
Correct |
2 ms |
4440 KB |
Output is correct |
23 |
Correct |
5 ms |
8028 KB |
Output is correct |
24 |
Correct |
5 ms |
8284 KB |
Output is correct |
25 |
Correct |
8 ms |
11868 KB |
Output is correct |
26 |
Correct |
8 ms |
12192 KB |
Output is correct |
27 |
Correct |
8 ms |
12120 KB |
Output is correct |
28 |
Correct |
3 ms |
5212 KB |
Output is correct |
29 |
Correct |
1 ms |
1196 KB |
Output is correct |
30 |
Correct |
8 ms |
11868 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
860 KB |
Output is correct |
12 |
Correct |
1 ms |
1628 KB |
Output is correct |
13 |
Correct |
1 ms |
1624 KB |
Output is correct |
14 |
Correct |
1 ms |
1884 KB |
Output is correct |
15 |
Correct |
1 ms |
2140 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
1116 KB |
Output is correct |
18 |
Correct |
1 ms |
1628 KB |
Output is correct |
19 |
Correct |
1 ms |
1116 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
3 ms |
4444 KB |
Output is correct |
22 |
Correct |
2 ms |
4440 KB |
Output is correct |
23 |
Correct |
5 ms |
8028 KB |
Output is correct |
24 |
Correct |
5 ms |
8284 KB |
Output is correct |
25 |
Correct |
8 ms |
11868 KB |
Output is correct |
26 |
Correct |
8 ms |
12192 KB |
Output is correct |
27 |
Correct |
8 ms |
12120 KB |
Output is correct |
28 |
Correct |
3 ms |
5212 KB |
Output is correct |
29 |
Correct |
1 ms |
1196 KB |
Output is correct |
30 |
Correct |
8 ms |
11868 KB |
Output is correct |
31 |
Runtime error |
32 ms |
25176 KB |
Execution killed with signal 11 |
32 |
Halted |
0 ms |
0 KB |
- |