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 fr first
#define sc second
#define clr(a, x) memset(a, x, sizeof(a))
#define dbg(x) cout<<"("<<#x<<"): "<<x<<endl;
#define printvector(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout<<*it<<" "; cout<<endl;
#define all(v) v.begin(), v.end()
#define lcm(a, b) (a * b)/__gcd(a, b)
#define int long long int
#define printvecpairs(vec) for(auto it: vec) cout<<it.fr<<' '<<it.sc<<endl;
#define endl '\n'
#define float long double
const int MOD = 1e9 + 7;
const int INF = 2e15;
const int MAXN = 3005;
int n, m;
int dp[MAXN][MAXN];
int modinv = 0;
int fastexpo(int b, int exp){
if(exp == 0) return 1;
if(exp == 1) return b;
int ans = (fastexpo(b,exp/2) % MOD);
ans *= ans;
ans %= MOD;
if(exp % 2 == 1){
ans *= b;
}
ans %= MOD;
return ans;
}
int nc2(int n){
int ans = n%MOD;
ans *= (n-1+MOD)%MOD;
ans %= MOD;
return ans*modinv;
}
int f(int lx, int ly){
if(lx < 0 || ly < 0) return 0;
if(lx == 0 || ly == 0) return 1;
if(dp[lx][ly] != -1) return dp[lx][ly];
return dp[lx][ly]= (((4*((lx%MOD)*(f(lx-1, ly-1)%MOD))%MOD)%MOD) + ((((ly-1)%MOD)*(lx%MOD)*(f(lx-1, ly-2)%MOD)%MOD)%MOD) + ((nc2(lx)%MOD)*(f(lx-2,ly-1)%MOD)%MOD) + ((f(lx, ly-1)%MOD)%MOD))%MOD;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#endif
cin>>n>>m;
clr(dp, -1);
modinv = fastexpo(2, MOD-2);
cout<<(f(n, m)+MOD-1)%MOD<<endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |