이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define MOD (ll)(1e9+7)
typedef long long int ll;
//each row <=2
//each col <=2
//cant have triangle
inline void mod(ll &x){
if(x>=MOD)x-=MOD;
}
ll eval(ll x){
return (x*(x-1))/2 %MOD;
}
ll dp[3001][3001];
ll solve(int h,int w){
if(dp[h][w]!=-1)return dp[h][w];
if(!h || !w)return 1;
ll res = solve(h-1,w); //empty row
res+=(solve(h-1,w-1) * 4LL * w %MOD); //single tent in a col
mod(res);
if(w>=2)res+=solve(h-1,w-2) * eval(w) %MOD;//two tents same row
mod(res);
if(h>=2)res+=(solve(h-2,w-1) * (h-1) %MOD) * w%MOD; //two tents same col
mod(res);
dp[h][w] = res;
//cout<<h<<" "<<w<<" "<<res<<'\n';
return res;
}
int main()
{
int h,w;
cin>>h>>w;
for(int i=0;i<=h;i++)
for(int j=0;j<=w;j++)dp[i][j] = -1;
cout<<(solve(h,w)+MOD-1)%MOD;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |