This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*input
1 2
*/
#include<bits/stdc++.h>
using namespace std;
const int N=3011;
const int mod=1e9+7;
#define int long long
const int inf=1e18;
#define pii pair<int, int>
#define f first
#define s second
#define mp make_pair
#define FOR(i, n) for(int i=1;i<=n;i++)
#define TRACE(x) cerr << #x << " = " << x << endl
//Trace prints the name of the variable and the value.
int dp[N][N];
int solve(int r, int c)
{
if(r<0||c<0) return 0;
if(r==0||c==0) return 1;
if(dp[r][c]!=-1) return dp[r][c];
int temp=solve(r, c-1);
temp+=(((r*(r-1))/2)*solve(r-2, c-1))%mod;temp%=mod;
temp+=(4*r*solve(r-1, c-1))%mod;temp%=mod;
temp+=((c-1)*r*solve(r-1, c-2));temp%=mod;
dp[r][c]=temp;return dp[r][c];
}
signed main()
{
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int r, c;cin>>r>>c;
for(int i=0;i<N;i++)
for(int j=0;j<N;j++) dp[i][j]=-1;
cout<<(solve(r, c)+mod-1)%mod;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |