Submission #1034110

# Submission time Handle Problem Language Result Execution time Memory
1034110 2024-07-25T09:50:24 Z anHiep Tents (JOI18_tents) C++14
0 / 100
0 ms 348 KB
#include <bits/stdc++.h>

using namespace std;

const int mod = 1e9 + 7;

int dp[3003][3003];
int dv;

int bp(int a, int b){
    if(b == 0) return 1;
    if(b == 1) return a;
    int k = bp(a, b/2);
    k = (k * k) % mod;
    if(b % 2 == 0) return k;
    return (a * k) % mod;
}

int cal(int i, int j){
    if(i < 0 || j < 0) return 0;
    if(dp[i][j] != 0) return dp[i][j];
    int ans = 0;
    ans = (ans + cal(i - 1, j)) % mod;
    ans = (ans + cal(i - 1, j - 2) * j % mod * (j - 1) % mod * dv % mod);
    ans = (ans + cal(i - 2, j - 1) * j % mod * (j - 1) % mod);
    ans = (ans + cal(i - 1, j - 1) * j % mod * 4 % mod);

    return dp[i][j] = ans;
}

int main(){
    int n, m;
    cin >> n >> m;
    dv = bp(2, mod - 2);
    for(int i = 0; i <= n; i++) dp[i][0] = 1;
    for(int i = 0; i <= m; i++) dp[0][i] = 1;
    cout << ((cal(n, m) - 1)% mod + mod)%mod;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -