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;
const int Mod = 1e9 + 7, Nmax = 3003;
typedef long long ll;
int inm(int x, int y) { return (ll)x*y%Mod; }
void add_to(int &x, int y) { x+=y; if(x>=Mod) x-=Mod; }
int n, m, i, j, dp[Nmax][Nmax];
int main()
{
// freopen("input", "r", stdin);
cin.sync_with_stdio(false);
cin >> n >> m;
for(i=0; i<=n || i<=m; ++i) dp[0][i] = dp[i][0] = 1;
for(i=1; i<=n; ++i)
for(j=1; j<=m; ++j)
{
dp[i][j] = dp[i-1][j];
if(j>=2) add_to(dp[i][j], inm(dp[i-1][j-2], j*(j-1)/2));
if(i>=2) add_to(dp[i][j], inm(dp[i-2][j-1], (i-1) * j));
add_to(dp[i][j], inm(4 * j, dp[i-1][j-1]));
}
add_to(dp[n][m], Mod-1);
cout << dp[n][m] << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |