제출 #235253

#제출 시각아이디문제언어결과실행 시간메모리
235253wwddTents (JOI18_tents)C++14
100 / 100
319 ms72568 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MN = 3030;
const ll M = 1e9+7;
ll mul(ll a, ll b) {return (a*b)%M;}
ll dp[MN][MN];
ll ds(int h, int w) {
	if(h == 0 || w == 0) {return 1;}
	if(h < 0 || w < 0) {return 0;}
	if(dp[h][w] != -1) {
		return dp[h][w];
	}
	ll res = ds(h-1,w)+mul(4*w,ds(h-1,w-1));
	if(h > 1) {
		res += mul(w*(h-1),ds(h-2,w-1));
	}
	if(w > 1) {
		res += mul(w*(w-1)/2,ds(h-1,w-2));
	}
	res %= M;
	return dp[h][w] = res;
}
int main() {
	ll h,w;
	cin >> h >> w;
	memset(dp,-1,sizeof(dp));
	ll res = ds(h,w);
	res--;
	res = ((res%M)+M)%M;
	cout << res << '\n';
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...