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 <bits/stdc++.h>
#define __DEBUG 0
#define all(c) (c).begin(), (c).end()
#define tr(c, it) for(auto it = c.begin(); it != c.end(); it++)
#define setAll(x, k) memset(x, k, sizeof(x))
#define rep(i, N) for(int i = 0; i < N; i++)
#define rep2(i, s, e) for(int i = s; i <= e; i++)
#define rep3(i, s, e, d) for(int i = s; d >= 0 ? i <= e : i >= e; i += d)
#define pb push_back
#define DBG2(x) if(__DEBUG) cerr << "<" << __LINE__ << "> " << #x << ": " << x << endl
#define DBG if(__DEBUG) cerr
#define pii pair<int, int>
#define int ll
using namespace std;
typedef long long ll;
const int mod = 1000000007;
int dp[3001][3001];
bool ch[3001][3001];
int rec(int H, int W){
if(H < 0 || W < 0)
return 0;
if(W == 0 || H == 0)
return 1;
if(ch[H][W])
return dp[H][W];
ch[H][W] = 1;
return dp[H][W] = ((rec(H, W - 1) + H * (H - 1) / 2 * rec(H - 2, W - 1) % mod) % mod
+ (H * (W - 1) * rec(H - 1, W - 2) % mod + 4 * H * rec(H - 1, W - 1) % mod) % mod) % mod;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
#if __DEBUG
freopen("in", "r", stdin);
freopen("out", "w", stdout);
freopen("debug", "w", stderr);
#endif
int H, W;
cin >> H >> W;
cout << rec(H, W) - 1 << endl;
#if __DEBUG
system(R"(notepad .\out)");
#endif
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |