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 pb push_back
#define dbg(x) cout << "reached here " << x << endl;
#define f first
#define s second
#define ll long long
using namespace std;
typedef pair<int, int> pii;
const int maxn = 3005, mod = 1e9+7;
ll dp[maxn][maxn];
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int h, w;
cin >> h >> w;
for (int i = 1; i <= h; ++i)
dp[i][1] = 4*i + i*(i-1)/2;
for (int i = 1; i <= w; ++i)
dp[1][i] = 4*i + i*(i-1)/2;
for (int i = 2; i <= h; ++i)
for (int j = 2; j <= w; ++j)
dp[i][j] = (dp[i][j-1] + (i*(i-1)/2)*(dp[i-2][j-1]+1) + i*(4*(dp[i-1][j-1]+1) + (j-1)*(dp[i-1][j-2]+1))) % mod;
cout << dp[h][w] << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |