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 fr(i, n, m) for(int i = (n); i < (m); i ++)
#define rfr(i, n, m) for(int i = (n); i >= (m); i --)
#define pb push_back
#define st first
#define nd second
#define pq priority_queue
#define all(x) begin(x), end(x)
#include <time.h>
#include <cmath>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
const int i_inf = 1e9;
const ll inf = 2e18;
const ll mod = 1e9+7;
const ld eps = 1e-13;
const ld pi = 3.14159265359;
const int mxn = 5e5;
mt19937 _rand(time(NULL));
clock_t z;
int main(){
int n, m;
cin >> n >> m;
ll dp[n+1][m+1];
memset(dp, 0, sizeof(dp));
fr(i, 0, n+1) dp[i][0] = 1;
fr(i, 0, m+1) dp[0][i] = 1;
fr(i, 1, n+1){
fr(j, 1, m+1){
dp[i][j] = dp[i-1][j];
if(j >= 2) dp[i][j] += dp[i-1][j-2]*j*(j-1)/2;
if(i >= 2) dp[i][j] += dp[i-2][j-1]*j*(i-1);
dp[i][j] += j*dp[i-1][j-1]*4;
dp[i][j] %= mod;
}
}
ll ans = (dp[n][m]-1+mod)%mod;
cout<<ans<<endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |