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>
using namespace std;
#define all(x) x.begin(), x.end()
#define ar array
#define pb push_back
#define ln '\n'
#define int long long
using i64 = long long;
template <class F, class _S>
bool chmin(F &u, const _S &v){
bool flag = false;
if ( u > v ){
u = v; flag |= true;
}
return flag;
}
template <class F, class _S>
bool chmax(F &u, const _S &v){
bool flag = false;
if ( u < v ){
u = v; flag |= true;
}
return flag;
}
const int Mod = 1e9 + 7;
template <typename _F, typename _S>
auto add(_F &x, const _S &y) -> void{
x = (x + y) % Mod;
if ( x < 0 ){
x += Mod;
}
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int h, w; cin >> h >> w;
vector <vector<int>> dp(h + 1, vector <int> (w + 1));
for ( int i = 0; i <= h; i++ ){
for ( int j = 0; j <= w; j++ ){
if ( !i || !j ){
dp[i][j] = 1;
continue;
}
add(dp[i][j], dp[i - 1][j - 1] * 4 * j + dp[i - 1][j]);
if ( i >= 2 ){
add(dp[i][j], dp[i - 2][j - 1] * (i - 1) * j);
}
if ( j >= 2 ){
add(dp[i][j], dp[i - 1][j - 2] * (j * (j - 1) / 2));
}
}
}
add(dp[h][w], -1);
cout << dp[h][w];
cout << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |