# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1158042 | nguyn | Tents (JOI18_tents) | C++20 | 104 ms | 70992 KiB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define F first
#define S second
#define pb push_back
#define pii pair<int,int>
const int N = 3e3 + 5;
const int mod = 1e9 + 7;
int n, m;
int f[N][N];
void add(int &x, int y) {
if (y < 0) x += mod;
x += y;
if (x >= mod) x -= mod;
}
signed main(){
ios_base::sync_with_stdio(false) ;
cin.tie(0) ; cout.tie(0) ;
if (fopen("INP.INP" ,"r")) {
freopen("INP.INP" ,"r" , stdin) ;
freopen("OUT.OUT" , "w" , stdout) ;
}
cin >> n >> m;
for (int i = 0; i <= max(m, n); i++) {
f[i][0] = f[0][i] = 1;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
add(f[i][j], (f[i - 1][j - 1] * 4 * j + f[i - 1][j]) % mod);
if (i > 1) add(f[i][j], f[i - 2][j - 1] * j % mod * (i - 1) % mod);
if (j > 1) add(f[i][j], f[i - 1][j - 2] * (j * (j - 1) / 2 % mod) % mod);
}
}
int res = f[n][m];
add(res, -1);
cout << res;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |