# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
83454 | tincamatei | Tents (JOI18_tents) | C++14 | 141 ms | 36224 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 MAX_N = 3000;
const int MOD = 1000000007;
int dp[1+MAX_N][1+MAX_N];
int main() {
#ifdef HOME
FILE *fin = fopen("input.in", "r");
FILE *fout = fopen("output.out", "w");
#else
FILE *fin = stdin;
FILE *fout = stdout;
#endif
int n, m;
fscanf(fin, "%d%d", &n, &m);
for(int i = 0; i <= MAX_N; ++i)
dp[0][i] = dp[i][0] = 1;
for(int i = 1; i <= MAX_N; ++i)
for(int j = 1; j <= MAX_N; ++j) {
dp[i][j] = ((long long)dp[i - 1][j - 1] * j * 4) % MOD;
if(i >= 2) dp[i][j] = ((long long)dp[i - 2][j - 1] * (i - 1) * j + dp[i][j]) % MOD;
if(j >= 2) dp[i][j] = ((long long)dp[i - 1][j - 2] * j * (j - 1) / 2 + dp[i][j]) % MOD;
dp[i][j] = ((long long)dp[i - 1][j] + dp[i][j]) % MOD;
}
fprintf(fout, "%d", (dp[n][m] - 1 + MOD) % MOD);
#ifdef HOME
fclose(fin);
fclose(fout);
#endif
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |