# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
198252 | quocnguyen1012 | Tents (JOI18_tents) | C++14 | 287 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>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
const int maxn = 3e3 + 5, mod = 1e9 + 7;
void add(int & a, int b)
{
a += b;
if (a >= mod) a -= mod;
if (a < 0) a += mod;
}
int mul(int a, int b)
{
return 1ll * a * b % mod;
}
int N, M;
int f[maxn][maxn];
signed main(void)
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
if (fopen("A.INP", "r")){
freopen("A.INP", "r", stdin);
freopen("A.OUT", "w", stdout);
}
cin >> N >> M;
for (int i = 0; i < maxn; ++i)
f[i][0] = 1, f[0][i] = 1;
for (int i = 1; i <= N; ++i){
for (int j = 1; j <= M; ++j){
int & res = f[i][j];
add(res,f[i - 1][j]);
add(res,mul(f[i - 1][j - 1],4 * j));
if (i > 1) add(res,mul(f[i - 2][j - 1],j * (i - 1)));
if (j > 1) add(res,mul(f[i - 1][j - 2],j * (j - 1) / 2));
}
}
add(f[N][M], -1);
cout << f[N][M] << '\n';
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |