#include <bits/stdc++.h>
using namespace std;
#define int long long
int mod = 1000000007;
signed main(){
ios_base::sync_with_stdio(false); cin.tie(nullptr);
int n, m; cin >> n >> m;
int dp[n+1][m+1];
for(int i=0; i<=n; ++i){
for(int j=0; j<=m; ++j){
dp[i][j] = ((!i) || (!j));
}
}
for(int i=1; i<=n; ++i){
for(int j=1; j<=m; ++j){
dp[i][j] += dp[i][j-1] + 4LL*i*dp[i-1][j-1];
dp[i][j] += j>1 ? i*(j-1LL)*dp[i-1][j-2] : 0LL;
dp[i][j] += i>1 ? ((i*(i-1LL))/2LL)*dp[i-2][j-1] : 0LL;
dp[i][j] %= mod;
}
}
cout << dp[n][m]-1LL << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
492 KB |
Output is correct |
7 |
Correct |
1 ms |
512 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
640 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
2 ms |
1004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
492 KB |
Output is correct |
7 |
Correct |
1 ms |
512 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
640 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
2 ms |
1004 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
84 ms |
44140 KB |
Output is correct |
16 |
Correct |
6 ms |
3180 KB |
Output is correct |
17 |
Correct |
19 ms |
10240 KB |
Output is correct |
18 |
Correct |
24 ms |
12532 KB |
Output is correct |
19 |
Correct |
98 ms |
51308 KB |
Output is correct |
20 |
Correct |
78 ms |
41068 KB |
Output is correct |
21 |
Correct |
51 ms |
27264 KB |
Output is correct |
22 |
Correct |
53 ms |
26988 KB |
Output is correct |
23 |
Correct |
29 ms |
14956 KB |
Output is correct |
24 |
Correct |
136 ms |
70764 KB |
Output is correct |
25 |
Correct |
103 ms |
52588 KB |
Output is correct |
26 |
Correct |
115 ms |
60268 KB |
Output is correct |
27 |
Correct |
130 ms |
68076 KB |
Output is correct |