Submission #43984

#TimeUsernameProblemLanguageResultExecution timeMemory
43984ruhanhabib39Tents (JOI18_tents)C++17
100 / 100
122 ms71340 KiB
#include <bits/stdc++.h> using namespace std; const int MX = 3000; const long long MOD = 1e9 + 7; long long dp[MX + 10][MX + 10]; long long calc(long long H, long long W) { for(int w = 0; w <= W; w++) { dp[0][w] = 1; } for(int h = 0; h <= H; h++) { dp[h][0] = 1; } for(int h = 1; h <= H; h++) { for(int w = 1; w <= W; w++) { long long zero = dp[h-1][w]; long long one = 4*w * dp[h-1][w-1] % MOD; long long two_horiz = 0, two_vert = 0; if(w >= 2) two_horiz = w*(w - 1) / 2 * dp[h-1][w-2] % MOD; if(h >= 2) two_vert = w * (h - 1) * dp[h-2][w-1] % MOD; dp[h][w] = (zero + one + two_horiz + two_vert) % MOD; } } return dp[H][W]; } int main() { long long H, W; cin >> H >> W; cout << (calc(H, W) + MOD - 1) % MOD << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...