제출 #861002

#제출 시각아이디문제언어결과실행 시간메모리
861002CookieTents (JOI18_tents)C++14
100 / 100
134 ms70996 KiB
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define vt vector
#define pb push_back
#define pii pair<int, int>
#define sz(dq) (int)dq.size()
#define forr(i, a, b) for(int i = a; i < b; i++)
#define fi first
#define se second
#define pll pair<ll, ll>
ifstream fin("store.inp");
ofstream fout("store.out");
const ll mxn = 5e5 + 5, inf = 1e9, mod = 1e9 + 7, sq = 800, mxv = 1e6 + 5, pr = 37, mod2 = 1e9 + 9, mod3 = 998244353;
//const int x[4] = {0, -1, 0, 1};
int n, m;
ll dp[3005][3005];
void add(ll &a, ll b){
    a += b;
    if(a >= mod)a %= mod;
}
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> m;
    for(int i = 0; i <= m; i++)dp[0][i] = 1;
    for(int i = 0; i <= n; i++)dp[i][0] = 1;
    for(ll i = 1; i <= n; i++){
        for(ll j = 1; j <= m; j++){
            add(dp[i][j], dp[i - 1][j - 1] * j * 4);
            if(j >= 2){
                add(dp[i][j], dp[i - 1][j - 2] * j * (j - 1) / 2);
            }if(i >= 2){
                add(dp[i][j], dp[i - 2][j - 1] * j * (i - 1));
            }add(dp[i][j], dp[i - 1][j]);
        }
    }
    
    cout << (dp[n][m] - 1 + mod) % mod;
    return(0);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...