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 int long long
#define fi first
#define pll pair<long long, long long>
#define se second
#define isz(a) (int)a.size()
using namespace std;
const long long inf = 1e18;
const int maxn = 3e3 + 5;
const int mod = 1e9 + 7;
int n, m, divi;
int cc[maxn][maxn];
long long binpow(int x, int y){
long long ans = 1;
while (y){
if (y & 1) ans = ans * x % mod;
x = x * x % mod; y >>= 1;
}
return ans;
}
int dp(int i, int j){
if (i < 0 || j < 0) return 0;
if (cc[i][j] != -1) return cc[i][j];
int ans = 0;
ans += dp(i - 1, j); ans %= mod;
ans += dp(i - 1, j - 2) * j % mod * (j - 1) % mod * divi % mod; ans %= mod;
ans += dp(i - 2, j - 1) * j % mod * (i - 1) % mod; ans %= mod;
ans += dp(i - 1, j - 1) * j % mod * 4 % mod; ans %= mod;
// cout << ans << endl;
// cout << i << " " << j << " " << cc[i][j] << endl;
return cc[i][j] = ans;
}
void solve(){
cin >> n >> m;
for (int i = 1; i <= n; ++i){
for (int j = 1; j <= m; ++j) cc[i][j] = -1;
}
divi = binpow(2, mod - 2);
for (int i = 0; i <= n; ++i) cc[i][0] = 1;
for (int i = 0; i <= m; ++i) cc[0][i] = 1;
// cc[1][1] = 4;
cout << ((dp(n, m) - 1)%mod + mod)%mod << "\n";
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t = 1; // cin >> t;
while (t--){
solve();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |