# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1034275 | toan2602 | Tents (JOI18_tents) | C++14 | 0 ms | 348 KiB |
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 int long long
const int mod = 1e9+7;
int n, m, dp[3005][3005];
int bp(int a, int b) {
int res = 1;
while(b) {
if(b & 1) res = res * a % mod;
a = a * a % mod;
b >>= 1;
}
return res;
}
void solve() {
cin >> n >> m;
dp[1][1] = 4;
int r2 = bp(2, mod-2);
dp[0][0] = dp[0][1] = dp[1][0] = 1;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if(i==1 && j==1) continue;
dp[i][j] = dp[i-1][j] + dp[i-1][j-1] * j %mod * 4, dp[i][j] %= mod;
if(j>=2)dp[i][j] += (dp[i-1][j-2] * m % mod * (n-1) %mod * r2), dp[i][j] %= mod;
if(i>=2)dp[i][j] += (dp[i-2][j-1] * n % mod * (m-1) %mod * r2), dp[i][j] %= mod;
}
}
cout << dp[n][m];
}
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
if(fopen("input.inp","r")){
freopen("input.inp", "r", stdin);
freopen("output.out", "w", stdout);
}
int t = 1;
// cin >> t;
while(t--) {
solve();
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |