#include <bits/stdc++.h> // PLEASE
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pp;
#define MAXN 3005
#define MAXM 1005
#define MAXP 25
#define A first
#define B second
#define MP make_pair
#define PB push_back
const ll INF = 2e9+13;
const ll MOD = 1e9+7;
ll mmul(ll a, ll b) { return (a*b)%MOD; }
ll madd(ll a, ll b) { return (a+b)%MOD; }
void up(ll &a, ll b) { a = madd(a, b); }
int N, M;
ll dp[MAXN][MAXN];
int main(void)
{
ios_base::sync_with_stdio(false);
cin.tie(0);
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++) {
up(dp[i][j], dp[i-1][j]);
up(dp[i][j], mmul(mmul(4LL, j), dp[i-1][j-1]));
if(i > 1) up(dp[i][j], mmul(mmul(i-1, j), dp[i-2][j-1]));
if(j > 1) up(dp[i][j], mmul((((j-1LL)*j)/2LL)%MOD, dp[i-1][j-2]));
}
cout << madd(dp[M][N], MOD-1) << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
360 KB |
Output is correct |
3 |
Correct |
2 ms |
544 KB |
Output is correct |
4 |
Correct |
2 ms |
1188 KB |
Output is correct |
5 |
Correct |
3 ms |
1188 KB |
Output is correct |
6 |
Correct |
3 ms |
1456 KB |
Output is correct |
7 |
Correct |
3 ms |
1456 KB |
Output is correct |
8 |
Correct |
3 ms |
1700 KB |
Output is correct |
9 |
Correct |
2 ms |
1700 KB |
Output is correct |
10 |
Correct |
4 ms |
2084 KB |
Output is correct |
11 |
Correct |
2 ms |
2084 KB |
Output is correct |
12 |
Correct |
5 ms |
2644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
360 KB |
Output is correct |
3 |
Correct |
2 ms |
544 KB |
Output is correct |
4 |
Correct |
2 ms |
1188 KB |
Output is correct |
5 |
Correct |
3 ms |
1188 KB |
Output is correct |
6 |
Correct |
3 ms |
1456 KB |
Output is correct |
7 |
Correct |
3 ms |
1456 KB |
Output is correct |
8 |
Correct |
3 ms |
1700 KB |
Output is correct |
9 |
Correct |
2 ms |
1700 KB |
Output is correct |
10 |
Correct |
4 ms |
2084 KB |
Output is correct |
11 |
Correct |
2 ms |
2084 KB |
Output is correct |
12 |
Correct |
5 ms |
2644 KB |
Output is correct |
13 |
Correct |
2 ms |
2644 KB |
Output is correct |
14 |
Correct |
9 ms |
10020 KB |
Output is correct |
15 |
Correct |
154 ms |
55604 KB |
Output is correct |
16 |
Correct |
12 ms |
55604 KB |
Output is correct |
17 |
Correct |
35 ms |
55604 KB |
Output is correct |
18 |
Correct |
45 ms |
55604 KB |
Output is correct |
19 |
Correct |
174 ms |
63400 KB |
Output is correct |
20 |
Correct |
141 ms |
63400 KB |
Output is correct |
21 |
Correct |
95 ms |
63400 KB |
Output is correct |
22 |
Correct |
120 ms |
63400 KB |
Output is correct |
23 |
Correct |
100 ms |
63400 KB |
Output is correct |
24 |
Correct |
238 ms |
71460 KB |
Output is correct |
25 |
Correct |
175 ms |
71460 KB |
Output is correct |
26 |
Correct |
204 ms |
71460 KB |
Output is correct |
27 |
Correct |
224 ms |
71460 KB |
Output is correct |