# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1161974 | trinm01 | Tents (JOI18_tents) | C++20 | 184 ms | 71344 KiB |
#include <bits/stdc++.h>
using namespace std;
#define int unsigned long long
#define ll long long
#define FOR(i, l, r) for (int i = (l); i <= (r); i++)
#define FOD(i, r, l) for (int i = (r); i >= (l); i--)
#define fi first
#define se second
#define pii pair<int, int>
const ll mod = 1e9 + 7;
const ll MAXN = 3 * 1e3 + 5;
const ll oo = 1e10;
const ll base = 320;
int m, n, f[MAXN][MAXN];
int dp(int i, int j)
{
if (i < 0 || j < 0)
return 0;
if (i == 0 || j == 0)
return 1;
if (f[i][j] != -1)
return f[i][j];
int a = 0;
if (i >= 1 && j >= 2)
a = ((dp(i - 1, j - 2) * ((j) * (j - 1) / 2) % mod)) % mod;
int b = 0;
if (i >= 2 && j >= 1)
b = (dp(i - 2, j - 1) * (i - 1) * j) % mod;
int c = 0;
if (i >= 1)
c = dp(i - 1, j);
int d = 0;
if (i >= 1 && j >= 1)
d = ((dp(i - 1, j - 1) * (j * 4) % mod)) % mod;
return f[i][j] = (a + b + c + d) % mod;
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
if (fopen(".INP", "r"))
{
freopen(".INP", "r", stdin);
freopen(".OUT", "w", stdout);
}
cin >> m >> n;
memset(f, -1, sizeof f);
cout << dp(m, n) - 1;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |