#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define all(x) (x).begin(),(x).end()
#define X first
#define Y second
#define sep ' '
#define endl '\n'
#define SZ(x) ll(x.size())
const ll MAXN = 3010;
const ll LOG = 22;
const ll INF = 8e18;
const ll MOD = 1e9 + 7; //998244353; //1e9 + 9;
ll n , m , dp[MAXN][MAXN];
int main() {
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
cin >> n >> m;
for(int i = 0 ; i <= n ; i++){
for(int j = 0 ; j <= m ; j++){
if(i == 0 || j == 0){
dp[i][j] = 1;
continue;
}
dp[i][j] = dp[i - 1][j];
dp[i][j] += 4 * j * dp[i - 1][j - 1];
if(j > 1) dp[i][j] += j * (j - 1) / 2 * dp[i - 1][j - 2];
if(i > 1) dp[i][j] += j * (i - 1) * dp[i - 2][j - 1];
dp[i][j] %= MOD;
}
}
cout << (dp[n][m] + MOD - 1) % MOD << endl;
return 0;
}
/*
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
1100 KB |
Output is correct |
5 |
Correct |
0 ms |
712 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 |
716 KB |
Output is correct |
10 |
Correct |
1 ms |
1740 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 |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
1100 KB |
Output is correct |
5 |
Correct |
0 ms |
712 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 |
716 KB |
Output is correct |
10 |
Correct |
1 ms |
1740 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 |
332 KB |
Output is correct |
14 |
Correct |
5 ms |
9684 KB |
Output is correct |
15 |
Correct |
41 ms |
55096 KB |
Output is correct |
16 |
Correct |
3 ms |
4044 KB |
Output is correct |
17 |
Correct |
10 ms |
12756 KB |
Output is correct |
18 |
Correct |
12 ms |
17108 KB |
Output is correct |
19 |
Correct |
45 ms |
62924 KB |
Output is correct |
20 |
Correct |
36 ms |
50828 KB |
Output is correct |
21 |
Correct |
26 ms |
33792 KB |
Output is correct |
22 |
Correct |
25 ms |
35368 KB |
Output is correct |
23 |
Correct |
19 ms |
26972 KB |
Output is correct |
24 |
Correct |
68 ms |
70904 KB |
Output is correct |
25 |
Correct |
52 ms |
61272 KB |
Output is correct |
26 |
Correct |
52 ms |
66636 KB |
Output is correct |
27 |
Correct |
53 ms |
69060 KB |
Output is correct |