#include<iostream>
#include<stdio.h>
#include<vector>
#include<cmath>
#include<queue>
#include<string.h>
#include<map>
#include<set>
#include<algorithm>
#define ll long long
#define pi pair < ll,ll >
#define mp(a,b) make_pair(a,b)
#define mid (low+high)/2
#define rep(i,a,b) for(int i = a;i < b;i++)
#define N 3004
#define INF 1e9+7
using namespace std;
ll n,m,mod=1e9+7;
ll dp[N][N];
ll solve(ll i,ll j)
{
if(i < 0 || j < 0)
return 0;
if(i==0||j==0)
return 1;
if(dp[i][j]!=-1)
return dp[i][j];
return dp[i][j] = ((solve(i-1,j-2)*(j*(j-1))/2)%mod + (solve(i-2,j-1)*(i-1)*j)%mod + (4*j*solve(i-1,j-1))%mod + (solve(i-1,j)))%mod;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
memset(dp,-1,sizeof dp);
cin >> n >> m;
cout << (solve(n,m)-1+mod)%mod << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
38 ms |
71036 KB |
Output is correct |
2 |
Correct |
40 ms |
70908 KB |
Output is correct |
3 |
Correct |
37 ms |
71032 KB |
Output is correct |
4 |
Correct |
38 ms |
71032 KB |
Output is correct |
5 |
Correct |
37 ms |
71032 KB |
Output is correct |
6 |
Correct |
38 ms |
71032 KB |
Output is correct |
7 |
Correct |
38 ms |
71032 KB |
Output is correct |
8 |
Correct |
37 ms |
71032 KB |
Output is correct |
9 |
Correct |
39 ms |
70920 KB |
Output is correct |
10 |
Correct |
39 ms |
71040 KB |
Output is correct |
11 |
Correct |
38 ms |
71040 KB |
Output is correct |
12 |
Correct |
41 ms |
71036 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
38 ms |
71036 KB |
Output is correct |
2 |
Correct |
40 ms |
70908 KB |
Output is correct |
3 |
Correct |
37 ms |
71032 KB |
Output is correct |
4 |
Correct |
38 ms |
71032 KB |
Output is correct |
5 |
Correct |
37 ms |
71032 KB |
Output is correct |
6 |
Correct |
38 ms |
71032 KB |
Output is correct |
7 |
Correct |
38 ms |
71032 KB |
Output is correct |
8 |
Correct |
37 ms |
71032 KB |
Output is correct |
9 |
Correct |
39 ms |
70920 KB |
Output is correct |
10 |
Correct |
39 ms |
71040 KB |
Output is correct |
11 |
Correct |
38 ms |
71040 KB |
Output is correct |
12 |
Correct |
41 ms |
71036 KB |
Output is correct |
13 |
Correct |
40 ms |
71032 KB |
Output is correct |
14 |
Correct |
38 ms |
71160 KB |
Output is correct |
15 |
Correct |
243 ms |
71160 KB |
Output is correct |
16 |
Correct |
40 ms |
71040 KB |
Output is correct |
17 |
Correct |
53 ms |
71036 KB |
Output is correct |
18 |
Correct |
79 ms |
71032 KB |
Output is correct |
19 |
Correct |
282 ms |
71240 KB |
Output is correct |
20 |
Correct |
202 ms |
71160 KB |
Output is correct |
21 |
Correct |
118 ms |
71032 KB |
Output is correct |
22 |
Correct |
165 ms |
71160 KB |
Output is correct |
23 |
Correct |
119 ms |
71288 KB |
Output is correct |
24 |
Correct |
333 ms |
71160 KB |
Output is correct |
25 |
Correct |
256 ms |
71288 KB |
Output is correct |
26 |
Correct |
304 ms |
71160 KB |
Output is correct |
27 |
Correct |
337 ms |
71288 KB |
Output is correct |