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 ll long long
ll mod=1e9+7;
ll mult(ll a, ll b){
return (a*b)%mod;
}
ll chose(ll x){
return ((x*(x-1))/2)%mod;
}
ll dp[3003][3003];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
ll n,m;
cin >> n >> m;
dp[0][0]=1;
for (ll i = 1; i<=n; i++)dp[i][0]=1;
for (ll i = 1; i<=m; i++)dp[0][i]=1;
for (ll i = 1; i<=n; i++){
for (ll j = 1; j<=m; j++){
dp[i][j]=dp[i-1][j];
dp[i][j]+=mult(4*j,dp[i-1][j-1]);
if (j>=2)dp[i][j]+=mult(chose(j),dp[i-1][j-2]);
if (i>=2)dp[i][j]+=mult(mult(i-1,j),dp[i-2][j-1]);
dp[i][j]=dp[i][j]%mod;
}
}
cout << (dp[n][m]+mod-1)%mod << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |