#include <bits/stdc++.h>
using namespace std;
#define FOR(i, l, r) for(int i = (l); i < (r); ++i)
#define ROF(i, r, l) for(int i = (r) - 1; i >= (l); --i)
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define all(v) begin(v), end(v)
#define rall(v) rbegin(v), rend(v)
#define pb push_back
#define eb emplace_back
#define sz(v) (int)v.size()
#define sum_of(v) accumulate(all(v), 0ll)
#define dbg(x) "[" #x " = " << (x) << "]"
template<typename T>
bool minimize(T& a, const T& b){
if(a > b) return a = b, true;
return false;
}
template<typename T>
bool maximize(T& a, const T& b){
if(a < b) return a = b, true;
return false;
}
using ll = long long;
using db = double;
using ld = long double;
using ull = unsigned long long;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using pd = pair<db, db>;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vl = vector<ll>;
using vd = vector<db>;
using vpi = vector<pi>;
using vpl = vector<pl>;
void setIO(){
ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef LOCAL
freopen("task.inp", "r", stdin);
freopen("task.out", "w", stdout);
#endif // LOCAL
}
const int mod = 1e9 + 7;
struct mint{
int v;
mint(int v = 0) : v(v) {}
friend bool operator == (const mint& a, const mint& b){ return a.v == b.v; }
friend bool operator != (const mint& a, const mint& b){ return a.v != b.v; }
mint& operator += (const mint& o){
v += o.v;
if(v >= mod) v -= mod;
return *this;
}
mint& operator -= (const mint& o){
v -= o.v;
if(v < 0) v += mod;
return *this;
}
mint& operator *= (const mint& o){
v = 1LL * v * o.v % mod;
return *this;
}
mint power(ll n) const{
mint result(1), base = *this;
for(; n > 0; n >>= 1, base *= base) if(n & 1) result *= base;
return result;
}
mint inv() const {
return power(mod - 2);
}
friend mint operator + (mint a, const mint& b){ return a += b; }
friend mint operator - (mint a, const mint& b){ return a -= b; }
friend mint operator * (mint a, const mint& b){ return a *= b; }
friend ostream& operator << (ostream& out, const mint& o){ return out << o.v; }
};
const int MAX = 3e3 + 5;
int H, W;
mint dp[MAX][MAX];
int main(){
setIO();
cin >> H >> W;
FOR(i, 0, W+1) dp[0][i] = 1;
FOR(i, 0, H+1) dp[i][0] = 1;
FOR(i, 1, H+1){
FOR(j, 1, W+1){
dp[i][j] += dp[i-1][j];
dp[i][j] += dp[i-1][j-1] * mint(4 * j);
if(i > 1) dp[i][j] += dp[i-2][j-1] * mint(j * (i-1));
if(j > 1) dp[i][j] += dp[i-1][j-2] * mint(j * (j-1) / 2);
}
}
mint result = dp[H][W];
result -= 1;
cout << result << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |