#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define show(x,y) cout << y << " " << #x << endl;
#define show2(x,y,i,j) cout << y << " " << #x << " " << j << " " << #i << endl;
#define show3(x,y,i,j,p,q) cout << y << " " << #x << " " << j << " " << #i << " " << q << " " << #p << endl;
#define show4(x,y) for(auto it:y) cout << it << " "; cout << #x << endl;
typedef pair<long long,int>pii;
typedef pair<pii,pii>pi2;
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
const int mod=1e9+7;
int memo[3005][3005];
int f(int n){
int hold=n*(n-1)/2;
hold=(hold+mod)%mod;
//show2(n,n,hold,hold);
return hold;
}
int dp(int a, int b){
if(a==0||b==0) return 1;
if(a<0||b<0) return 0;
if(memo[a][b]!=-1) return memo[a][b];
int ans=0;
ans=(ans+dp(a-1,b));
if(a>=2&&b>=1){
int hold=dp(a-2,b-1)*(a-1)*b;
hold%=mod;
ans=(ans+hold)%mod;
}
if(a>=1&&b>=2){
int hold=dp(a-1,b-2)*f(b);
hold%=mod;
ans=(ans+hold)%mod;
}
if(a>=1&&b>=1){
int hold=dp(a-1,b-1)*4*b;
hold%=mod;
ans=(ans+hold)%mod;
}
return memo[a][b]=ans;
}
void solve(){
int n,k;
cin >> n >> k;
memset(memo,-1,sizeof(memo));
cout << dp(n,k);
}
int32_t main(){
ios::sync_with_stdio(0);
cin.tie(0);
int t=1;
//freopen("in.txt","w",stdout);
//cin >> t;
while(t--){
solve();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
18 ms |
71004 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
18 ms |
71004 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |