# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
109693 | IOrtroiii | Tents (JOI18_tents) | C++14 | 159 ms | 35832 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;
const int N = 3030;
const int mod = 1e9 + 7;
void add(int &x,int y) {
x += y; if (x >= mod) x -= mod;
}
int mul(int x,int y) {
return (long long) x * y % mod;
}
int f[N][N];
int main() {
int n, m; scanf("%d %d", &n, &m);
f[m][n] = 1;
for (int i = m; i >= 0; --i) {
for (int j = n; j >= 0; --j) {
if (i) {
add(f[i - 1][j], f[i][j]);
if (j) add(f[i - 1][j - 1], mul(mul(4, j), f[i][j]));
if (j > 1) add(f[i - 1][j - 2], mul(mul(j, j - 1), mul(mod + 1 >> 1, f[i][j])));
if (i > 1 && j) add(f[i - 2][j - 1], mul(mul(j, i - 1), f[i][j]));
} else if (j) add(f[i][j - 1], f[i][j]);
}
}
printf("%d\n", (f[0][0] + mod - 1) % mod);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |