제출 #1210749

#제출 시각아이디문제언어결과실행 시간메모리
1210749boss_zzTents (JOI18_tents)C++20
100 / 100
97 ms70980 KiB
#include<bits/stdc++.h> #define rep(a,b,c) for(ll a=b;a<=c;++a) #define ll long long #define ff first #define ss second #define mp make_pair using namespace std; typedef pair<int,int> pii; typedef pair<ll,ll> pll; const ll N=3005,inf=1e18,mod=1e9+7; ll n,m,dp[N][N],fac[N],inv[N]; ll fpow(ll a,ll b){ ll res=1; while(b){ if(b&1) (res*=a)%=mod; (a*=a)%=mod; b>>=1; } return res; } void build(){ fac[0]=1; rep(i,1,N-5) (fac[i]=fac[i-1]*i)%=mod; inv[N-5]=fpow(fac[N-5],mod-2); for(ll i=N-6;i>=0;--i) (inv[i]=inv[i+1]*(i+1))%=mod; } ll C(ll n,ll k) {return fac[n]*inv[k]%mod*inv[n-k]%mod;} signed main(){ ios::sync_with_stdio(0);cin.tie(0); cin>>n>>m; build(); dp[0][0]=1; rep(i,1,n) dp[i][0]=1; rep(i,1,m) dp[0][i]=1; rep(i,1,n){ rep(j,1,m){ dp[i][j]+=dp[i-1][j]; (dp[i][j]+=dp[i-1][j-1]*j*4)%=mod; if(i>1) (dp[i][j]+=dp[i-2][j-1]*(i-1)*j)%=mod; if(j>1) (dp[i][j]+=dp[i-1][j-2]*C(j,2))%=mod; } } cout<<(dp[n][m]-1+mod)%mod<<'\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...