Submission #1016512

#TimeUsernameProblemLanguageResultExecution timeMemory
1016512fryingducTents (JOI18_tents)C++17
100 / 100
88 ms35668 KiB
#include "bits/stdc++.h"
using namespace std;

const int maxn = 3005;
const int mod = 1e9 + 7;
int w, h;
int f[maxn][maxn];

int add(int x, int y) {
    if(y < 0) y += mod;
    x = x + y;
    if(x >= mod) x -= mod;
    return x;
}
int c2(int x) {
    return 1ll * x * (x - 1) / 2 % mod;
}
void solve() {
    cin >> h >> w;
    for(int i = 0; i <= h; ++i) f[i][0] = 1;
    for(int i = 0; i <= w; ++i) f[0][i] = 1;
    for(int i = 1; i <= h; ++i) {
        for(int j = 1; j <= w; ++j) {
            // add one tent
            f[i][j] = 1ll * f[i - 1][j - 1] * j % mod * 4 % mod; 
            
            // add two tents in same row 
            f[i][j] = add(f[i][j], 1ll * f[i - 2][j - 1] * (i - 1) % mod * j % mod);
            
            // add two tents in same col 
            f[i][j] = add(f[i][j], 1ll * f[i - 1][j - 2] * c2(j) % mod);
            
            // do nothing
            f[i][j] = add(f[i][j], f[i - 1][j]);
        }
    }
    
    cout << add(f[h][w], -1);
}
signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    solve();
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...