# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
151071 | karma | Tents (JOI18_tents) | C++14 | 11 ms | 8440 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>
#define ll long long
#define pb emplace_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
const int N = int(1e3) + 2;
const int mod = int(1e9) + 7;
int f[N][N], n, m;
int add(int& x, int y) {if((x += y) >= mod) x -= mod;}
int mul(int x, int y) {return 1ll * x * y % mod;}
int DP(int r, int c)
{
if(f[r][c] != -1) return f[r][c];
if(r * c == 0) return f[r][c] = 1;
int& res = f[r][c];
res = DP(r - 1, c); // 0 in row r
add(res, mul(DP(r - 1, c - 1), 4 * c)); // 1 in row r
if(r >= 2) add(res, mul(DP(r - 2, c - 1), (r - 1) * c)); // 1 in row r, 1 in (r - 1) rows, same column
if(c >= 2) add(res, mul(DP(r - 1, c - 2), c * (c - 1) / 2)); // same row r
return res;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
if(fopen("test.inp", "r")) {
freopen("test.inp", "r", stdin);
freopen("test.out", "w", stdout);
}
memset(&f, -1, sizeof f);
cin >> n >> m;
cout << (DP(n, m) - 1 + mod) % mod;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |