#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
using namespace std;
const int mxn=1e5+5;
const int inf=1e9;
const ll mod=1e9+7;
ll nc2(ll n) {
ll res= n * (n-1) /2 % mod;
return res % mod;
}
int main() {
int h,w;
cin>>h>>w;
ll dp[h+1][w+1];
for(int i=1;i<=w;i++) {
dp[1][i] = ( 4 * i + nc2(i) + 1) % mod ;
dp[0][i]=1;
}
for(int i=1;i<=h;i++) {
dp[i][1] = ( 4 * i + nc2(i) + 1) % mod;
dp[i][0]=1;
}
for(int i=2;i<=h;i++) {
for(int j=2;j<=w;j++) {
dp[i][j] = 4 * j * dp[i-1][j-1] % mod;
//cout<<dp[i][j]<<endl;
dp[i][j] += nc2(j) * dp[i-1][j-2] % mod;
dp[i][j] %= mod;
//cout<<dp[i][j]<<endl;
dp[i][j] += (j * (i-1) % mod) * dp[i-2][j-1] % mod;
dp[i][j] %= mod;
dp[i][j] = (dp[i][j] + dp[i-1][j]) % mod;
}
}
cout<<(dp[h][w] - 1 + mod) % mod<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
512 KB |
Output is correct |
7 |
Correct |
1 ms |
512 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
256 KB |
Output is correct |
10 |
Correct |
1 ms |
640 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
1024 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
512 KB |
Output is correct |
7 |
Correct |
1 ms |
512 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
256 KB |
Output is correct |
10 |
Correct |
1 ms |
640 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
1024 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
127 ms |
44152 KB |
Output is correct |
16 |
Correct |
8 ms |
3200 KB |
Output is correct |
17 |
Correct |
28 ms |
10112 KB |
Output is correct |
18 |
Correct |
34 ms |
12408 KB |
Output is correct |
19 |
Correct |
142 ms |
51448 KB |
Output is correct |
20 |
Correct |
111 ms |
41080 KB |
Output is correct |
21 |
Correct |
73 ms |
27128 KB |
Output is correct |
22 |
Correct |
72 ms |
26744 KB |
Output is correct |
23 |
Correct |
40 ms |
14968 KB |
Output is correct |
24 |
Correct |
194 ms |
70776 KB |
Output is correct |
25 |
Correct |
144 ms |
52600 KB |
Output is correct |
26 |
Correct |
164 ms |
60280 KB |
Output is correct |
27 |
Correct |
188 ms |
68088 KB |
Output is correct |