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;
const int N = 3005;
const int MOD = 1000000007;
inline int add(int a, int b){return (a+b>=MOD)?a+b-MOD:a+b;}
inline void inc(int& a, int b){a = add(a, b);}
inline int sub(int a, int b){return (a-b<0)?a-b+MOD:a-b;}
inline void dec(int &a, int b){a = sub(a, b);}
inline int mul(int a, int b){return 1ll*a*b%MOD;}
inline void grow(int &a, int b){a = mul(a, b);}
int n, m, dp[N][N];
int main(){
// freopen("a.in", "r", stdin);
cin.tie(0)->sync_with_stdio(0);
cin >> n >> m;
for(int i = 0; i<=n; ++i)
for(int j = 0; j<=m; ++j){
if(i==0 || j==0)
{dp[i][j] = 1; continue;}
// no take - 0
inc(dp[i][j], dp[i][j-1]);
// no take - 1
if(i>=2) inc(dp[i][j], mul(dp[i-1][j-1], 4*i-4));
// no take - 2
if(i>=3) inc(dp[i][j], mul(dp[i-2][j-1], (i-1)*(i-2)/2));
// no take - 2*
if(i>=2 && j>=2) inc(dp[i][j], mul(dp[i-1][j-2], (i-1)*(j-1)));
// take - 0 0
inc(dp[i][j], mul(dp[i-1][j-1], 4));
// take - 1 0
if(i>=2) inc(dp[i][j], mul(dp[i-2][j-1], i-1));
// take - 0 1
if(j>=2) inc(dp[i][j], mul(dp[i-1][j-2], j-1));
}
cout << sub(dp[n][m], 1) << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |