#include<bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
using namespace std;
using ll=long long;
const ll MOD=1000000007LL;
template<typename T> void chmax(T &a,T b){a=max(a,b);}
template<typename T> void chmin(T &a,T b){a=min(a,b);}
vector<ll> f,fi;
ll mpow(ll x,ll n){
ll res=1;
while(n>0){
if(n&1){
res*=x;
res%=MOD;
}
x*=x;
x%=MOD;
n>>=1;
}
return res;
}
void comb(ll n){
f.resize(n+10);
fi.resize(n+10);
f[0]=1;
for(ll i=1;i<=n;i++){
f[i]=f[i-1]*i%MOD;
}
fi[n]=mpow(f[n],MOD-2);
for(ll i=n-1;i>=0;i--){
fi[i]=fi[i+1]*(i+1LL)%MOD;
}
}
ll ncr(ll n,ll r){
return f[n]*fi[r]%MOD*fi[n-r]%MOD;
}
int main(){
ll h,w;cin>>h>>w;
comb(h+w);
vector<vector<ll>> dp(h+10,vector<ll>(w+10));
dp[0][w]=1;
for(ll i=1;i<=h;i++){
for(ll j=0;j<=w;j++){
dp[i][j]+=dp[i-1][j];
if(j<w){
dp[i][j]+=dp[i-1][j+1]*(j+1LL)%MOD*4LL%MOD;
if(j<w-1){
dp[i][j]+=dp[i-1][j+2]*((j+2LL)*(j+1LL)/2LL)%MOD;
}
}
dp[i][j]%=MOD;
}
}
ll ans=0;
for(ll i=0;i<=h/2;i++){//横かぶりの個数
ll s=1;
for(ll j=h;j>h-i*2;j-=2){
s*=ncr(j,2);
s%=MOD;
}
for(ll j=0;j<=w;j++){//残り列数
if(i==0&&j==w)continue;
if(j<i)continue;
ans+=dp[h-i*2][j]*s%MOD*ncr(j,i)%MOD;
ans%=MOD;
}
}
cout<<ans<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
6 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
512 KB |
Output is correct |
6 |
Correct |
3 ms |
512 KB |
Output is correct |
7 |
Correct |
2 ms |
512 KB |
Output is correct |
8 |
Correct |
2 ms |
512 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
3 ms |
640 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
1024 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
6 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
512 KB |
Output is correct |
6 |
Correct |
3 ms |
512 KB |
Output is correct |
7 |
Correct |
2 ms |
512 KB |
Output is correct |
8 |
Correct |
2 ms |
512 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
3 ms |
640 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
1024 KB |
Output is correct |
13 |
Correct |
3 ms |
512 KB |
Output is correct |
14 |
Correct |
6 ms |
640 KB |
Output is correct |
15 |
Correct |
110 ms |
44664 KB |
Output is correct |
16 |
Correct |
13 ms |
3328 KB |
Output is correct |
17 |
Correct |
30 ms |
10368 KB |
Output is correct |
18 |
Correct |
31 ms |
12672 KB |
Output is correct |
19 |
Correct |
127 ms |
51832 KB |
Output is correct |
20 |
Correct |
128 ms |
41848 KB |
Output is correct |
21 |
Correct |
69 ms |
27644 KB |
Output is correct |
22 |
Correct |
69 ms |
27404 KB |
Output is correct |
23 |
Correct |
43 ms |
15480 KB |
Output is correct |
24 |
Correct |
168 ms |
71416 KB |
Output is correct |
25 |
Correct |
154 ms |
53240 KB |
Output is correct |
26 |
Correct |
157 ms |
60968 KB |
Output is correct |
27 |
Correct |
175 ms |
68748 KB |
Output is correct |