Submission #797908

#TimeUsernameProblemLanguageResultExecution timeMemory
797908vjudge1Tents (JOI18_tents)C++17
48 / 100
2058 ms65324 KiB
#include<bits/stdc++.h>

using namespace std;
using ll = long long;

const int MOD = 1e9 + 7;

void norm(ll &x) {
    if(x >= MOD) x -= MOD;
    if(x < 0) x += MOD;
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int h, w;
    cin >> h >> w;
    vector<vector<ll>> dp(w + 10, vector<ll>(w + 10));
    dp[0][0] = 1;
    for(ll i = 1; i <= h; i++) {
        vector<vector<ll>> new_dp(w + 10, vector<ll>(w + 10));
        for(ll j = 0; j <= w; j++) {
            for(ll k = 0; k <= j; k++) {
                ll val = dp[j][k];
                if(!val) continue;
                new_dp[j][k] += val,
                norm(new_dp[j][k]);
                new_dp[j + 2][k] += (w - j) * (w - j - 1) / 2 * val % MOD,
                norm(new_dp[j + 2][k]);
                new_dp[j + 1][k] += (w - j) * 4 * val % MOD; 
                norm(new_dp[j + 1][k]);
                new_dp[j + 1][k + 1] += val * (w - j) % MOD;
                norm(new_dp[j + 1][k + 1]);
                if(!k) continue;
                new_dp[j][k - 1] += val * k % MOD;
                norm(new_dp[j][k - 1]);
            }
        }
        dp = new_dp;
    }
    ll ans = 0;
    for(int j = 1; j <= w; j++) ans += dp[j][0], norm(ans);
    cout << ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...