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>
#define el '\n'
#define fi first
#define sc second
#define int ll
#define pii pair<int, int>
#define all(v) v.begin(), v.end()
using namespace std;
using ll=long long;
using ull=unsigned long long;
using ld=long double;
const int mod=1e9+7;
const int N=3e3+11;
int m, n, dp[N][N];
void sol()
{
cin >> m >> n;
for(int i=0;i<=m;i++) dp[i][0]=1;
for(int i=0;i<=n;i++) dp[0][i]=1;
for(int i=1;i<=m;i++)
{
for(int j=1;j<=n;j++)
{
dp[i][j]=(dp[i][j]+4*j*dp[i-1][j-1])%mod; // dat 1
if(i>=2) dp[i][j]=(dp[i][j]+j*(i-1)*dp[i-2][j-1])%mod; // dat 2 cai cung hang
if(j>=2) dp[i][j]=(dp[i][j]+j*(j-1)/2*dp[i-1][j-2])%mod; // dat 2 cai cung cot
dp[i][j]=(dp[i][j]+dp[i-1][j])%mod; // ko dat gi
}
}
cout << (dp[m][n]-1+mod)%mod;
}
signed main()
{
// freopen("divisor.INP", "r", stdin);
// freopen("divisor.OUT", "w", stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
int t=1;
//cin >> t;
while(t--)
{
sol();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |