#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = 1000000007;
signed main(){
ios_base::sync_with_stdio(false);
int h, w;
cin>>h>>w;
int dp[h+1][w+1];
dp[1][1] = 5;
for(int i = 0;i<=h;i++) dp[i][0] = 1;
for(int i = 0;i<=w;i++) dp[0][i] = 1;
for(int i = 2;i<=h;i++){
dp[i][1] = dp[i-1][1] + (i-1) + 4;
}
for(int j = 2;j<=w;j++){
for(int i = 1;i<=h;i++){
dp[i][j] = dp[i][j-1];
dp[i][j]%=MOD;
dp[i][j] += (((i*(j-1))%MOD)*dp[i-1][j-2])%MOD;
dp[i][j]%=MOD;
dp[i][j] += (4*i*dp[i-1][j-1])%MOD;
dp[i][j]%=MOD;
if(i>1) dp[i][j] += ((((i*(i-1))/2)%MOD) * (dp[i-2][j-1]))%MOD;
dp[i][j]%=MOD;
}
}
int ans = (dp[h][w] - 1 + MOD)%MOD;
cout<<ans<<"\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
512 KB |
Output is correct |
6 |
Correct |
5 ms |
512 KB |
Output is correct |
7 |
Correct |
5 ms |
512 KB |
Output is correct |
8 |
Correct |
5 ms |
512 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
640 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
7 ms |
1024 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
512 KB |
Output is correct |
6 |
Correct |
5 ms |
512 KB |
Output is correct |
7 |
Correct |
5 ms |
512 KB |
Output is correct |
8 |
Correct |
5 ms |
512 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
640 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
7 ms |
1024 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
225 ms |
44284 KB |
Output is correct |
16 |
Correct |
13 ms |
3200 KB |
Output is correct |
17 |
Correct |
32 ms |
10112 KB |
Output is correct |
18 |
Correct |
44 ms |
12408 KB |
Output is correct |
19 |
Correct |
275 ms |
51416 KB |
Output is correct |
20 |
Correct |
201 ms |
41208 KB |
Output is correct |
21 |
Correct |
123 ms |
27128 KB |
Output is correct |
22 |
Correct |
136 ms |
26744 KB |
Output is correct |
23 |
Correct |
51 ms |
14976 KB |
Output is correct |
24 |
Correct |
331 ms |
70904 KB |
Output is correct |
25 |
Correct |
258 ms |
52600 KB |
Output is correct |
26 |
Correct |
286 ms |
60280 KB |
Output is correct |
27 |
Correct |
342 ms |
68216 KB |
Output is correct |