이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |