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 file_io freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define fast_io ios::sync_with_stdio(false);cin.tie(0);
#define what(x) cerr << #x << " is " << x << endl;
#define kill(x) {cout << x << '\n'; return 0;}
#define all(x) (x).begin(), (x).end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define ll long long
#define F first
#define S second
const ll inf = 8e18, mod = 1e9 + 7, delta = 1e8, SQ = 700; //998244353
using namespace std;
const ll N = 3e3 + 10, LG = 20;
ll dp[N][N];
int32_t main() {
fast_io;
int n, m;
cin >> n >> m;
dp[0][0] = 1;
dp[1][1] = 5;
for (int i = 1; i <= n; i++) dp[i][0] = 1;
for (int i = 1; i <= m; i++) dp[0][i] = 1;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (i == 1 && j == 1) continue;
dp[i][j] = dp[i - 1][j];
dp[i][j] += (4 * j * dp[i - 1][j - 1] % mod);
dp[i][j] %= mod;
if (i >= 2) dp[i][j] += (j * (i - 1) * dp[i - 2][j - 1] % mod);
dp[i][j] %= mod;
if (j >= 2) dp[i][j] += (j * (j - 1) / 2 * dp[i - 1][j - 2] % mod);
dp[i][j] %= mod;
}
}
cout << dp[n][m] - 1 << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |