Submission #922692

#TimeUsernameProblemLanguageResultExecution timeMemory
922692Alihan_8Tents (JOI18_tents)C++17
100 / 100
95 ms71004 KiB
#include <bits/stdc++.h>

using namespace std;

#define all(x) x.begin(), x.end()
#define ar array
#define pb push_back
#define ln '\n'
#define int long long

using i64 = long long;

template <class F, class _S>
bool chmin(F &u, const _S &v){
    bool flag = false;
    if ( u > v ){
        u = v; flag |= true;
    }
    return flag;
}

template <class F, class _S>
bool chmax(F &u, const _S &v){
    bool flag = false;
    if ( u < v ){
        u = v; flag |= true;
    }
    return flag;
}

const int Mod = 1e9 + 7;

template <typename _F, typename _S>
auto add(_F &x, const _S &y) -> void{
    x = (x + y) % Mod;
    if ( x < 0 ){
        x += Mod;
    }
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int h, w; cin >> h >> w;
    vector <vector<int>> dp(h + 1, vector <int> (w + 1));
    for ( int i = 0; i <= h; i++ ){
        for ( int j = 0; j <= w; j++ ){
            if ( !i || !j ){
                dp[i][j] = 1;
                continue;
            }
            add(dp[i][j], dp[i - 1][j - 1] * 4 * j + dp[i - 1][j]);
            if ( i >= 2 ){
                add(dp[i][j], dp[i - 2][j - 1] * (i - 1) * j);
            }
            if ( j >= 2 ){
                add(dp[i][j], dp[i - 1][j - 2] * (j * (j - 1) / 2));
            }
        }
    }
    add(dp[h][w], -1);
    cout << dp[h][w];

    cout << '\n';
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...