#include<bits/stdc++.h>
#define el '\n'
#define fi first
#define sc second
#define int ll
#define pii pair<int, int>
#define all(v) v.begin(), v.end()
using namespace std;
using ll=long long;
using ull=unsigned long long;
using ld=long double;
const int mod=1e9+7;
const int N=3e3+11;
int m, n, dp[N][N];
void sol()
{
cin >> m >> n;
for(int i=0;i<=m;i++) dp[i][0]=1;
for(int i=0;i<=n;i++) dp[0][i]=1;
for(int i=1;i<=m;i++)
{
for(int j=1;j<=n;j++)
{
dp[i][j]=(dp[i][j]+4*j*dp[i-1][j-1])%mod; // dat 1
if(i>=2) dp[i][j]=(dp[i][j]+j*(i-1)*dp[i-2][j-1])%mod; // dat 2 cai cung hang
if(j>=2) dp[i][j]=(dp[i][j]+j*(j-1)/2*dp[i-1][j-2])%mod; // dat 2 cai cung cot
dp[i][j]=(dp[i][j]+dp[i-1][j])%mod; // ko dat gi
}
}
cout << (dp[m][n]-1+mod)%mod;
}
signed main()
{
// freopen("divisor.INP", "r", stdin);
// freopen("divisor.OUT", "w", stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
int t=1;
//cin >> t;
while(t--)
{
sol();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
8540 KB |
Output is correct |
11 |
Correct |
0 ms |
2396 KB |
Output is correct |
12 |
Correct |
2 ms |
8568 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
8540 KB |
Output is correct |
11 |
Correct |
0 ms |
2396 KB |
Output is correct |
12 |
Correct |
2 ms |
8568 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
5 ms |
55644 KB |
Output is correct |
15 |
Correct |
43 ms |
66140 KB |
Output is correct |
16 |
Correct |
3 ms |
6492 KB |
Output is correct |
17 |
Correct |
10 ms |
17016 KB |
Output is correct |
18 |
Correct |
13 ms |
29272 KB |
Output is correct |
19 |
Correct |
50 ms |
70236 KB |
Output is correct |
20 |
Correct |
35 ms |
59992 KB |
Output is correct |
21 |
Correct |
27 ms |
39608 KB |
Output is correct |
22 |
Correct |
28 ms |
51804 KB |
Output is correct |
23 |
Correct |
20 ms |
70492 KB |
Output is correct |
24 |
Correct |
60 ms |
70996 KB |
Output is correct |
25 |
Correct |
51 ms |
62040 KB |
Output is correct |
26 |
Correct |
57 ms |
66896 KB |
Output is correct |
27 |
Correct |
59 ms |
69460 KB |
Output is correct |