Submission #1369881

#TimeUsernameProblemLanguageResultExecution timeMemory
1369881Born_To_LaughTents (JOI18_tents)C++17
100 / 100
71 ms71064 KiB
// Born_To_Laugh - Hughie Do
#include <bits/stdc++.h>
#define alle(AC) AC.begin(), AC.end()
#define fi first
#define se second
using namespace std;
typedef long long ll;
[[maybe_unused]] const int MOD = 1e9 + 7, INF = 1e9 + 7;
const int maxn = 3010;
int n, m;
ll dp[maxn][maxn];
void solve(){
    cin >> n >> m;
    dp[0][0] = 1;
    for(int i=1; i<=max(n, m); ++i){
        dp[i][0] = dp[0][i] = 1;
    }
    for(int i=1; i<=n; ++i){
        for(int j=1; j<=m; ++j){
            dp[i][j] += dp[i][j - 1];
            dp[i][j] += dp[i - 1][j - 1] * i * 4 % MOD;
            if(j - 2 >= 0){
                dp[i][j] += dp[i - 1][j - 2] * i * (j - 1) % MOD;
            }
            if(i - 2 >= 0){
                dp[i][j] += dp[i - 2][j - 1] * i * (i - 1) / 2 % MOD;
            }
            dp[i][j] %= MOD;
            // cout << i << ' ' << j << ' ' << dp[i][j] << '\n';
        }
    }
    cout << (dp[n][m] - 1 + MOD) % MOD << '\n';
}
signed main(){
    // freopen("inp.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
}
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...