Submission #1033919

#TimeUsernameProblemLanguageResultExecution timeMemory
1033919vjudge1Tents (JOI18_tents)C++17
100 / 100
100 ms70996 KiB
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pb push_back
#define ii pair<int, int>
#define sz(v) (int)v.size()
#define all(v) v.begin(), v.end()
using namespace std;

const int N=3e3+5, mod = 1e9+7, inf = 1e18;

int m, n, dp[N][N];

signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> m >> n;
    for (int i=0; i<=m; i++) dp[i][0]=1;
    for (int i=0; i<=n; i++) dp[0][i]=1;
    for (int i=1; i<=m; i++) {
        for (int j=1; j<=n; j++) {
            dp[i][j]=(dp[i][j]+4*j*dp[i-1][j-1])%mod;
            if(i>=2) dp[i][j]=(dp[i][j]+j*(i-1)*dp[i-2][j-1])%mod;
            if(j>=2) dp[i][j]=(dp[i][j]+j*(j-1)/2*dp[i-1][j-2])%mod;
            dp[i][j]=(dp[i][j]+dp[i-1][j])%mod;
        }
    }
    cout << (dp[m][n]-1+mod)%mod;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...