#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 |
1 |
Correct |
2 ms |
4700 KB |
Output is correct |
2 |
Correct |
1 ms |
4700 KB |
Output is correct |
3 |
Correct |
2 ms |
4700 KB |
Output is correct |
4 |
Correct |
2 ms |
5468 KB |
Output is correct |
5 |
Correct |
2 ms |
4956 KB |
Output is correct |
6 |
Correct |
2 ms |
5504 KB |
Output is correct |
7 |
Correct |
2 ms |
4956 KB |
Output is correct |
8 |
Correct |
2 ms |
5724 KB |
Output is correct |
9 |
Correct |
2 ms |
4956 KB |
Output is correct |
10 |
Correct |
3 ms |
5980 KB |
Output is correct |
11 |
Correct |
1 ms |
4700 KB |
Output is correct |
12 |
Correct |
4 ms |
6348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4700 KB |
Output is correct |
2 |
Correct |
1 ms |
4700 KB |
Output is correct |
3 |
Correct |
2 ms |
4700 KB |
Output is correct |
4 |
Correct |
2 ms |
5468 KB |
Output is correct |
5 |
Correct |
2 ms |
4956 KB |
Output is correct |
6 |
Correct |
2 ms |
5504 KB |
Output is correct |
7 |
Correct |
2 ms |
4956 KB |
Output is correct |
8 |
Correct |
2 ms |
5724 KB |
Output is correct |
9 |
Correct |
2 ms |
4956 KB |
Output is correct |
10 |
Correct |
3 ms |
5980 KB |
Output is correct |
11 |
Correct |
1 ms |
4700 KB |
Output is correct |
12 |
Correct |
4 ms |
6348 KB |
Output is correct |
13 |
Correct |
1 ms |
4700 KB |
Output is correct |
14 |
Correct |
6 ms |
13956 KB |
Output is correct |
15 |
Correct |
115 ms |
59216 KB |
Output is correct |
16 |
Correct |
9 ms |
8028 KB |
Output is correct |
17 |
Correct |
26 ms |
16732 KB |
Output is correct |
18 |
Correct |
33 ms |
21232 KB |
Output is correct |
19 |
Correct |
130 ms |
66788 KB |
Output is correct |
20 |
Correct |
104 ms |
54868 KB |
Output is correct |
21 |
Correct |
72 ms |
37992 KB |
Output is correct |
22 |
Correct |
69 ms |
39560 KB |
Output is correct |
23 |
Correct |
43 ms |
31064 KB |
Output is correct |
24 |
Correct |
174 ms |
74740 KB |
Output is correct |
25 |
Correct |
132 ms |
65276 KB |
Output is correct |
26 |
Correct |
148 ms |
70484 KB |
Output is correct |
27 |
Correct |
165 ms |
73024 KB |
Output is correct |