This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define all int i=0; i<n; i++
#define INF LLONG_MAX
#define Nirvana ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl '\n'
#define mod 1000000007
#define ll long long int
#define int ll
#define T int t;cin>>t;while(t--)
int dp[3001][3001];
int rec(int i, int j){
if(i<0 || j<0)return 0;
if(i==0 || j==0)return 1;
if(dp[i][j])return dp[i][j];
dp[i][j] += (4*j*rec(i-1, j-1))%mod;
dp[i][j]%=mod;
dp[i][j] += (rec(i-1, j));
dp[i][j]%=mod;
dp[i][j] += (((j*(j-1))/2) * (rec(i-1, j-2)))%mod;
dp[i][j]%=mod;
dp[i][j] += (j*(i-1) * rec(i-2, j-1));
dp[i][j]%=mod;
return dp[i][j];
}
signed main(){
Nirvana;
int n,m;
cin>>n>>m;
cout<<(rec(n, m)-1 + mod)%mod<<endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |