Submission #582744

#TimeUsernameProblemLanguageResultExecution timeMemory
582744elkernosTents (JOI18_tents)C++17
100 / 100
124 ms70916 KiB
#include <bits/stdc++.h>

using namespace std;

const int mod = 1000 * 1000 * 1000 + 7;

int main()
{
    cin.tie(nullptr)->sync_with_stdio(0);
    int h, w;
    cin >> h >> w;
    vector<vector<long long>> dp(h + 1, vector<long long>(w + 1));
    auto C2 = [](int x) {
        return x * (x - 1) / 2;
    };
    for(int i = 0; i <= h; i++) {
        for(int j = 0; j <= w; j++) {
            if(i == 0 || j == 0) {
                dp[i][j] = 1;
                continue;
            }
            dp[i][j] += dp[i][j - 1];
            dp[i][j] += 4ll * i * dp[i - 1][j - 1];
            if(i >= 2) {
                dp[i][j] += C2(i) * dp[i - 2][j - 1];
            }
            if(j >= 2) {
                dp[i][j] += i * (j - 1) * dp[i - 1][j - 2];
            }
            dp[i][j] %= mod;
        }
    }
    cout << (dp[h][w] - 1 + mod) % mod << "\n";
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...