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 ll long long
#define fi first
#define se second
#define sz(x) (int)x.size()
#define ALL(v) v.begin(),v.end()
#define MASK(k) (1LL << (k))
#define BIT(x, i) (((x) >> (i)) & 1)
#define oo (ll)1e18
#define INF (ll)1e9
#define MOD (ll)(1e9 + 7)
using namespace std;
template<class T1, class T2>
bool maximize(T1 &a, T2 b){if(a < b){a = b; return true;} return false;}
template<class T1, class T2>
bool minimize(T1 &a, T2 b){if(a > b){a = b; return true;} return false;}
template<class T1, class T2>
void add(T1 &a, T2 b){a += b; if(a >= MOD) a -= MOD;}
template<class T1, class T2>
void sub(T1 &a, T2 b){a -= b; if(a < 0) a += MOD;}
template<class T>
void cps(T &v){sort(ALL(v)); v.resize(unique(ALL(v)) - v.begin());}
const int MAX = 4e3 + 10;
int N, M;
int dp[MAX][MAX];
void solve(){
cin >> N >> M;
for(int i = 0; i <= N; i++) dp[i][0] = 1;
for(int i = 0; i <= M; i++) dp[0][i] = 1;
for(int i = 1; i <= N; i++){
for(int j = 1; j <= M; j++){
add(dp[i][j], dp[i - 1][j]);
add(dp[i][j], 4LL * j * dp[i - 1][j - 1] % MOD);
if(j >= 2) add(dp[i][j], 1LL * dp[i - 1][j - 2] * (1LL * j * (j - 1) / 2 % MOD) % MOD);
if(i >= 2) add(dp[i][j], 1LL * dp[i - 2][j - 1] * (i - 1) % MOD * j % MOD);
}
}
int ans = dp[N][M];
sub(ans, 1);
cout << ans << '\n';
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
// freopen("CAU3.inp","r",stdin);
// freopen("CAU3.out","w",stdout);
int t = 1;
// cin >> t;
while(t--){
solve();
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |