Submission #1356177

#TimeUsernameProblemLanguageResultExecution timeMemory
1356177kokorooLego Wall (EGOI22_legowall)C++20
62 / 100
11 ms13892 KiB
#include<bits/stdc++.h>
//#include<atcoder/all>

using namespace std;
//using namespace atcoder;
#define rep(i,n) for(ll i=0; i<n; i++)
#define rrep(i,n) for(ll i=n-1; i>=0; i--)
#define print(a) cout<<a<<endl
typedef long long ll;
#define yn(flg) if(flg){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define YN(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define so(a) sort(a.begin(),a.end())
#define mp make_pair
#define vi vector<int>
#define vl vector<ll>
#define vs vector<string>
#define pb push_back
#define a2i(a,s) (ll)(a-s)
#define i2a(s,a) (char)(s+a)
#define ssize(a) a.size()
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<pair<ll,ll>,ll> P3;
typedef pair<pair<ll,ll>,pair<ll,ll>> P4;

typedef pair<ll, ll> Pll;
typedef pair<ll,Pll> Plll;
typedef pair<Pii, int> Piii;
const ll INF = 1000000000000000000;

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;

}

ll MOD=1000000007;

int main(){
//入力

	cin.tie(0);
	ios::sync_with_stdio(0);

	ll h,w;
	cin>>w>>h;

//判定1
	if(w<=h*h){
		vector<ll> ALL(w+1,1);
		ALL[1]=1;
		for(ll i=2;i<=w;i++){
			ALL[i]=(ALL[i-1]+ALL[i-2])%MOD;
		}
		for(ll i=1;i<=w;i++){

			ll p=ALL[i];
			for(ll j=1;j<h;j++)p=(p*ALL[i])%MOD;
			ALL[i]=p;
		}

		vector<ll> dp(w+1,0);
		dp[1]=1;
		for(ll j=1;j<=w;j++){
			ll sum=0;
			for(ll k=1;k<j;k++){
				ll dame=(dp[k]*ALL[j-k])%MOD;
				sum=(sum+dame)%MOD;
			}
			dp[j]=(ALL[j]-sum+MOD)%MOD;
		}

		cout<<dp[w]<<endl;
	}else{
		vector<vector<ll> > dp(w+1,vector<ll>(h+1,0));
		vector<vector<ll> > c(h+1,vector<ll>(h+1,1));

		c[1][1]=1;
		for(ll i=1;i<=h;i++){
			for(ll j=1;j<=i;j++){
				if(i==1&&j==1)continue;
				c[i][j]=(c[i-1][j]+c[i-1][j-1])%MOD;
			}
		}

		for(ll i=1;i<w;i++){
			for(ll j=1;j<=h;j++){
				ll p=0;
				for(ll k=1;k<=h;k++){
					if(h-k<j)break;
					p=(p+dp[i-1][k]*c[h-k][j])%MOD;
				}
				dp[i][j]=p;
			}
		}
		ll sum=0;
		for(ll i=1;i<=h;i++)sum=(sum+dp[w-1][i])%MOD;

		cout<<sum<<endl;
	}


	 return 0;
}
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...