This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <cstdio>
using namespace std;
const int MAXD = 3003;
int dp[MAXD][MAXD];
typedef long long ll;
const int MOD = 1000000007;
int ADD(ll a, ll b){
return (a+b)%MOD;
}
int SUB(ll a, ll b){
return (a+MOD-b)%MOD;
}
int MUL(ll a, ll b){
return (a*b)%MOD;
}
int solve(int h, int w){
int& r = dp[h][w];
if(r == -1){
if(h == 0 || w == 0){
r = 1;
}else{
r = ADD(solve(h, w-1), MUL(4*h, solve(h-1, w-1)));
if(h >= 2) r = ADD(r, MUL(h*(h-1)/2, solve(h - 2, w - 1)));
if(w >= 2) r = ADD(r, MUL(h*(w-1), solve(h - 1, w - 2)));
}
}
return r;
}
int main(){
for(int i=0;i<MAXD;++i) for(int j=0;j<MAXD;++j) dp[i][j] = -1;
int h,w;
scanf("%d%d", &h, &w);
printf("%d\n", SUB(solve(h, w), 1));
}
Compilation message (stderr)
tents.cpp: In function 'int main()':
tents.cpp:40:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &h, &w);
~~~~~^~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |