#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
long long dp[4004][4004];
int main() {
int n,m;
cin >> n >> m;
for(int i=0; i<=m; i++) {
dp[0][i] = 1;
}
for(int i=1; i<=n; i++) {
for(int j=0; j<=m; j++) {
dp[i][j] += dp[i-1][j];
if(j>=1) {
dp[i][j] += ((dp[i-1][j-1] * j)%mod * 4)%mod;
dp[i][j] %= mod;
}
if(j>=1 && i>=2) {
dp[i][j] += ((dp[i-2][j-1] * j)%mod * (i-1))%mod;
dp[i][j] %= mod;
}
if(i>=1 && j>=2) {
dp[i][j] += (dp[i-1][j-2] * (j*(j-1)/2)%mod)%mod;
dp[i][j] %= mod;
}
}
}
cout << dp[n][m]-1 << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
1108 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
1364 KB |
Output is correct |
7 |
Correct |
1 ms |
724 KB |
Output is correct |
8 |
Correct |
1 ms |
1364 KB |
Output is correct |
9 |
Correct |
1 ms |
724 KB |
Output is correct |
10 |
Correct |
1 ms |
1748 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
2200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
1108 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
1364 KB |
Output is correct |
7 |
Correct |
1 ms |
724 KB |
Output is correct |
8 |
Correct |
1 ms |
1364 KB |
Output is correct |
9 |
Correct |
1 ms |
724 KB |
Output is correct |
10 |
Correct |
1 ms |
1748 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
2200 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
4 ms |
9648 KB |
Output is correct |
15 |
Correct |
94 ms |
55156 KB |
Output is correct |
16 |
Correct |
7 ms |
4096 KB |
Output is correct |
17 |
Correct |
23 ms |
12812 KB |
Output is correct |
18 |
Correct |
29 ms |
17012 KB |
Output is correct |
19 |
Correct |
117 ms |
62856 KB |
Output is correct |
20 |
Correct |
113 ms |
50916 KB |
Output is correct |
21 |
Correct |
86 ms |
33752 KB |
Output is correct |
22 |
Correct |
59 ms |
35404 KB |
Output is correct |
23 |
Correct |
44 ms |
27088 KB |
Output is correct |
24 |
Correct |
164 ms |
82708 KB |
Output is correct |
25 |
Correct |
122 ms |
62864 KB |
Output is correct |
26 |
Correct |
140 ms |
71420 KB |
Output is correct |
27 |
Correct |
158 ms |
79632 KB |
Output is correct |