Submission #1301039

#TimeUsernameProblemLanguageResultExecution timeMemory
1301039baotoan655Tents (JOI18_tents)C++20
100 / 100
51 ms70948 KiB
#include <bits/stdc++.h>
#define file(name)  if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
using namespace std;

#define int long long
const int N = 3005;
const int MOD = 1e9 + 7;
int h, w;
int dp[N][N];

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

//    file("A") else file("task");

    cin >> h >> w;
    for(int i = 0; i <= w; i++) dp[0][i] = 1;
    for(int i = 1; i <= h; i++) {
        dp[i][0] = 1;
        for(int j = 1; j <= w; j++) {
            dp[i][j] = dp[i - 1][j] + 4 * j * dp[i - 1][j - 1];
            if(i >= 2) dp[i][j] += dp[i - 2][j - 1] * j * (i - 1);
            if(j >= 2) dp[i][j] += dp[i - 1][j - 2] * j * (j - 1) / 2;
            dp[i][j] %= MOD;
        }
    }
    cout << (dp[h][w] - 1 + MOD) % MOD;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...