Submission #1033969

#TimeUsernameProblemLanguageResultExecution timeMemory
1033969fimhTents (JOI18_tents)C++14
100 / 100
265 ms59344 KiB
#include <bits/stdc++.h>
#define int long long
#define fi first
#define pll pair<long long, long long>
#define se second
#define isz(a) (int)a.size()
using namespace std;

const long long inf = 1e18;
const int maxn = 3e3 + 5;
const int mod = 1e9 + 7;

int n, m, divi;
int cc[maxn][maxn];

long long binpow(int x, int y){
    long long ans = 1;
    while (y){
        if (y & 1) ans = ans * x % mod;
        x = x * x % mod; y >>= 1;
    }
    return ans;
}

int dp(int i, int j){
    if (i < 0 || j < 0) return 0;
    if (cc[i][j]) return cc[i][j];
    int &ans = cc[i][j];
    ans += dp(i - 1, j); ans %= mod;
    ans += dp(i - 1, j - 1) * 4 % mod * j % mod; ans %= mod;
    ans += dp(i - 1, j - 2) * j % mod * (j - 1) % mod * divi % mod; ans %= mod;
    ans += dp(i - 2, j - 1) * j % mod * (i - 1) % mod; ans %= mod;
    return ans;
}   

void solve(){
    cin >> n >> m;
    divi = binpow(2, mod - 2);
    for (int i = 0; i <= n; ++i) cc[i][0] = 1;
    for (int i = 0; i <= m; ++i) cc[0][i] = 1;
    int ans = (dp(n, m) - 1 + mod) % mod;
    cout << ans << "\n";
}   

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int t = 1; // cin >> t;
    while (t--){
        solve();
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...