#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
using namespace std;
const ll mod=1e9+7;
ll dp[3005][3005],n,m;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
cin>>n>>m;
for (int i=0; i<=max(n,m); i++){
dp[i][0]=1; dp[0][i]=1;
}
for (int i=1; i<=n; i++)
for (int j=1; j<=m; j++){
dp[i][j]=dp[i-1][j]+dp[i-1][j-1]*j*4%mod;
if (i>1) dp[i][j]+=dp[i-2][j-1]*j*(i-1)%mod;
if (j>1) dp[i][j]+=dp[i-1][j-2]*j*(j-1)/2%mod;
dp[i][j]%=mod;
}
cout<<dp[n][m]-1<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
1116 KB |
Output is correct |
3 |
Correct |
0 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
1116 KB |
Output is correct |
5 |
Correct |
1 ms |
1372 KB |
Output is correct |
6 |
Correct |
1 ms |
1372 KB |
Output is correct |
7 |
Correct |
1 ms |
1376 KB |
Output is correct |
8 |
Correct |
1 ms |
1372 KB |
Output is correct |
9 |
Correct |
1 ms |
860 KB |
Output is correct |
10 |
Correct |
1 ms |
1884 KB |
Output is correct |
11 |
Correct |
1 ms |
1628 KB |
Output is correct |
12 |
Correct |
1 ms |
2140 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
1116 KB |
Output is correct |
3 |
Correct |
0 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
1116 KB |
Output is correct |
5 |
Correct |
1 ms |
1372 KB |
Output is correct |
6 |
Correct |
1 ms |
1372 KB |
Output is correct |
7 |
Correct |
1 ms |
1376 KB |
Output is correct |
8 |
Correct |
1 ms |
1372 KB |
Output is correct |
9 |
Correct |
1 ms |
860 KB |
Output is correct |
10 |
Correct |
1 ms |
1884 KB |
Output is correct |
11 |
Correct |
1 ms |
1628 KB |
Output is correct |
12 |
Correct |
1 ms |
2140 KB |
Output is correct |
13 |
Correct |
3 ms |
7768 KB |
Output is correct |
14 |
Correct |
5 ms |
9820 KB |
Output is correct |
15 |
Correct |
60 ms |
55184 KB |
Output is correct |
16 |
Correct |
6 ms |
9564 KB |
Output is correct |
17 |
Correct |
18 ms |
17612 KB |
Output is correct |
18 |
Correct |
18 ms |
17852 KB |
Output is correct |
19 |
Correct |
67 ms |
62904 KB |
Output is correct |
20 |
Correct |
56 ms |
51024 KB |
Output is correct |
21 |
Correct |
39 ms |
35408 KB |
Output is correct |
22 |
Correct |
38 ms |
35416 KB |
Output is correct |
23 |
Correct |
22 ms |
27228 KB |
Output is correct |
24 |
Correct |
94 ms |
70996 KB |
Output is correct |
25 |
Correct |
74 ms |
61264 KB |
Output is correct |
26 |
Correct |
78 ms |
66704 KB |
Output is correct |
27 |
Correct |
88 ms |
69152 KB |
Output is correct |