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 se second
#define fs first
#define pb push_back
#define ll long long
#define ii pair<ll,ll>
#define ld long double
#define SZ(v) (int)v.size()
#define ALL(v) v.begin(), v.end()
#define bit(msk, i) ((msk >> i) & 1)
#define iter(id, v) for(auto id : v)
#define rep(i,m,n) for(int i=(m); i<=(n); i++)
#define reb(i,m,n) for(int i=(m); i>=(n); i--)
using namespace std;
mt19937_64 rd(chrono :: steady_clock :: now().time_since_epoch().count());
ll Rand(ll l, ll r) { return uniform_int_distribution<ll> (l, r)(rd); }
const int N = 3e3 + 7;
const ll Mod = 1e9 + 7;
const int szBL = 916;
const ll INF = 1e9;
const int BASE = 137;
int n, m;
ll dp[N][N], f[N][N];
ll fac[(int)1e5 + 7];
ll power (ll n, ll m) {
if (m == 0) return 1;
ll t = power(n, m >> 1);
(t *= t) %= Mod;
if (m & 1) (t *= n % Mod) %= Mod;
return t;
}
ll C (int r, int n) {
if (r > n) return 0;
return fac[n] * power (fac[r], Mod - 2) % Mod * power (fac[n - r], Mod - 2) % Mod;
}
void fac_init () {
fac[0] = 1;
rep (i, 1, 1e5) fac[i] = fac[i - 1] * i % Mod;
}
void solution () {
fac_init();
cin >> n >> m;
dp[0][m] = 1;
rep (i, 1, n) {
rep (j, 0, m) {
(dp[i][j] += dp[i - 1][j + 1] * (j + 1) %Mod * 4 % Mod) %= Mod;
if (j + 2 <= m) (dp[i][j] += dp[i - 1][j + 2] * ((1LL * (j + 2) * (j + 1) / 2) % Mod) % Mod) %= Mod;
if (i - 2 >= 0 && j + 1 <= m) (dp[i][j] += dp[i - 2][j + 1] * (i - 1) % Mod * (j + 1) % Mod) %= Mod;
}
}
ll res = 0;
rep (i, 0, n) {
ll delta = C(i, n);
rep (j, 0, m) {
(res += dp[i][j] * delta % Mod ) %= Mod;
}
}
cout << res - 1<<"\n";
}
#define file(name) freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout);
int main () {
// file("c");
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll num_Test = 1;
// cin >> num_Test;
while(num_Test--)
solution();
}
/*
18 3
2 5
6 21
13 19
9 17
14 17
19 20
2 16
2 10
9 14
19 20
14 16
1 3
17 19
14 21
18 19
4 7
5 12
1 13
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |