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 printv(a, b) { \
for(auto pv : a) b << pv << " "; \
b << "\n"; \
}
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
ll C2(ll n){
if(n < 2) return 0;
return n * (n - 1) / 2;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<vector<ll>> dp(n + 1, vector<ll>(m + 1));
for(int i = 0; i <= n; i++) dp[i][0] = 1;
for(int i = 0; i <= m; i++) dp[0][i] = 1;
for(int sz = 2; sz <= n + m; sz++){
for(int i = 1; i < sz; i++){
int j = sz - i;
if(i > n || j > m) continue;
if(j >= 2) dp[i][j] += dp[i - 1][j - 2] * i % MOD * (j - 1) % MOD;
if(i >= 2) dp[i][j] += dp[i - 2][j - 1] * C2(i) % MOD;
dp[i][j] += 4LL * i * dp[i - 1][j - 1] % MOD;
dp[i][j] += dp[i][j - 1];
dp[i][j] %= MOD;
}
}
//for(int i = 0; i <= n; i++) printv(dp[i], cerr);
ll ans = dp[n][m];
ans--;
ans = (ans % MOD + MOD) % MOD;
cout << ans << "\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |