# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1151938 | mingga | Tents (JOI18_tents) | C++20 | 116 ms | 70820 KiB |
#include "bits/stdc++.h"
using namespace std;
#define ln "\n"
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define int long long
const int mod = 1e9 + 7;
const int inf = 2e18;
const int N = 3005;
int w, h, dp[N][N];
int add(int x, int y) {
x += y;
if(x >= mod) x -= mod;
return x;
}
int mul(int x, int y) {
x %= mod, y %= mod;
return (x * y) % mod;
}
int c2(int x) {
int a = x, b = x - 1;
if(a % 2) b /= 2;
else a /= 2;
return mul(a, b);
}
signed main() {
cin.tie(0) -> sync_with_stdio(0);
#define task ""
if(fopen(task ".INP", "r")) {
freopen(task ".INP", "r", stdin);
freopen(task ".OUT", "w", stdout);
}
cin >> w >> h;
dp[0][0] = 1;
for(int i = 1; i <= w; i++) {
dp[i][0] = 1;
}
for(int i = 1; i <= h; i++) {
dp[0][i] = 1;
}
for(int i = 1; i <= w; i++) {
for(int j = 1; j <= h; j++) {
dp[i][j] = add(dp[i][j], dp[i - 1][j]);
dp[i][j] = add(dp[i][j], mul(dp[i - 1][j - 1], 4 * j));
if(i > 1) dp[i][j] = add(dp[i][j], mul((i - 1) * j, dp[i - 2][j - 1]));
if(j > 1) dp[i][j] = add(dp[i][j], mul(c2(j), dp[i - 1][j - 2]));
}
}
cout << (dp[w][h] - 1 + mod) % mod << ln;
cerr << "\nTime: " << clock() * 1000 / CLOCKS_PER_SEC;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |