#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define fi first
#define se second
#define ll long long
#define pb push_back
#define ii pair<int,int>
template <class T>
using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int nax=3e3+5;
const int MOD=1e9+7;
#define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
long long dp[nax][nax];
long long dfs(ll x,ll y){
if(x<0||y<0) return 0;
if(x==0) return 1;
if(dp[x][y]) return dp[x][y];
dp[x][y]+=dfs(x-1,y-2)*(y*(y-1)/2)%MOD;
dp[x][y]%=MOD;
dp[x][y]+=dfs(x-1,y)%MOD;
dp[x][y]%=MOD;
dp[x][y]+=dfs(x-1,y-1)*(y*4)%MOD;
dp[x][y]%=MOD;
dp[x][y]+=dfs(x-2,y-1)*(y*(x-1))%MOD;
dp[x][y]%=MOD;
return dp[x][y];
}
int main()
{
optimise;
int n,m;
cin>>n>>m;
dp[0][0]=1;
cout << dfs(n,m)-1<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
452 KB |
Output is correct |
4 |
Correct |
1 ms |
1116 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
1372 KB |
Output is correct |
7 |
Correct |
1 ms |
856 KB |
Output is correct |
8 |
Correct |
1 ms |
1372 KB |
Output is correct |
9 |
Correct |
0 ms |
980 KB |
Output is correct |
10 |
Correct |
1 ms |
1884 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
2 ms |
2140 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 |
452 KB |
Output is correct |
4 |
Correct |
1 ms |
1116 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
1372 KB |
Output is correct |
7 |
Correct |
1 ms |
856 KB |
Output is correct |
8 |
Correct |
1 ms |
1372 KB |
Output is correct |
9 |
Correct |
0 ms |
980 KB |
Output is correct |
10 |
Correct |
1 ms |
1884 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
2 ms |
2140 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
4 ms |
9820 KB |
Output is correct |
15 |
Correct |
117 ms |
47444 KB |
Output is correct |
16 |
Correct |
2 ms |
1624 KB |
Output is correct |
17 |
Correct |
12 ms |
7004 KB |
Output is correct |
18 |
Correct |
29 ms |
13756 KB |
Output is correct |
19 |
Correct |
136 ms |
53328 KB |
Output is correct |
20 |
Correct |
106 ms |
42140 KB |
Output is correct |
21 |
Correct |
56 ms |
25412 KB |
Output is correct |
22 |
Correct |
69 ms |
30912 KB |
Output is correct |
23 |
Correct |
58 ms |
26432 KB |
Output is correct |
24 |
Correct |
166 ms |
58960 KB |
Output is correct |
25 |
Correct |
116 ms |
49236 KB |
Output is correct |
26 |
Correct |
138 ms |
54608 KB |
Output is correct |
27 |
Correct |
159 ms |
56956 KB |
Output is correct |