#include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
#define ull unsigned ll
using namespace std;
const int NMAX = 3001;
const ll mod = 1e9 + 7;
ll dp[NMAX][NMAX];
int main(){
int n, m; cin >> n >> m;
dp[0][0] = 1;
for(int i= 0; i <= n; i++) dp[i][0] = 1;
for(int j = 0; j <= m; j++) dp[0][j] = 1;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
dp[i][j] += dp[i - 1][j - 1] * 4 * j;
dp[i][j] += dp[i - 1][j];
if(i >= 2) dp[i][j] += dp[i - 2][j - 1] * j * (i - 1);
if(j >= 2) dp[i][j] += dp[i - 1][j - 2] * j * (j - 1) / 2;
dp[i][j] %= mod;
}
}
cout << (dp[n][m] - 1 + mod) % mod;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
308 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 |
564 KB |
Output is correct |
6 |
Correct |
1 ms |
1296 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 |
1712 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
2132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
308 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 |
564 KB |
Output is correct |
6 |
Correct |
1 ms |
1296 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 |
1712 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
2132 KB |
Output is correct |
13 |
Correct |
0 ms |
308 KB |
Output is correct |
14 |
Correct |
4 ms |
9600 KB |
Output is correct |
15 |
Correct |
53 ms |
55132 KB |
Output is correct |
16 |
Correct |
4 ms |
4052 KB |
Output is correct |
17 |
Correct |
11 ms |
12816 KB |
Output is correct |
18 |
Correct |
14 ms |
16972 KB |
Output is correct |
19 |
Correct |
72 ms |
62940 KB |
Output is correct |
20 |
Correct |
45 ms |
50848 KB |
Output is correct |
21 |
Correct |
31 ms |
33696 KB |
Output is correct |
22 |
Correct |
30 ms |
35408 KB |
Output is correct |
23 |
Correct |
21 ms |
26944 KB |
Output is correct |
24 |
Correct |
67 ms |
70660 KB |
Output is correct |
25 |
Correct |
64 ms |
61048 KB |
Output is correct |
26 |
Correct |
63 ms |
66508 KB |
Output is correct |
27 |
Correct |
69 ms |
68856 KB |
Output is correct |