#include <bits/stdc++.h>
#define rep(a, b, c) for (int a = (b); (a) <= (c); a++)
#define per(a, b, c) for (int a = (b); (a) >= (c); a--)
#define nl '\n'
#define ioi exit(0);
const int mod = (int)1e9 + 7;
const int N = (int)1e4;
using namespace std;
void add(int &x, int y) {
x += y;
if (x >= mod) x -= mod;
if (x < 0) x += mod;
}
int sum(int x, int y) {
add(x, y);
return x;
}
int n, m;
int dp[3001][3001];
int calc(int v = n, int free = m) {
if (!v) return 1;
if (~dp[v][free]) return dp[v][free];
int res = calc(v - 1, free);
// put < or > or ^ or v
if (free > 0) {
add(res, calc(v - 1, free - 1) * 1ll * free * 4 % mod);
// connect v and ^
if (v > 1) add(res, calc(v - 2, free - 1) * 1ll * (v - 1) * free % mod);
}
// connect > and <
if (free > 1) add(res, calc(v - 1, free - 2) * 1ll * (free * (free - 1) / 2) % mod);
return dp[v][free] = res;
}
int main() {
#ifdef IOI
freopen ("in.txt", "r", stdin);
freopen ("slow.out", "w", stdout);
#endif
cin >> n >> m;
memset(dp, -1, sizeof(dp));
int ans = sum(calc(), -1);
cout << ans << nl;
ioi
}
/*
5116 0
3720 1
450 2
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
31 ms |
35576 KB |
Output is correct |
2 |
Correct |
31 ms |
35576 KB |
Output is correct |
3 |
Correct |
31 ms |
35576 KB |
Output is correct |
4 |
Correct |
37 ms |
35704 KB |
Output is correct |
5 |
Correct |
37 ms |
35576 KB |
Output is correct |
6 |
Correct |
38 ms |
35576 KB |
Output is correct |
7 |
Correct |
32 ms |
35576 KB |
Output is correct |
8 |
Correct |
37 ms |
35576 KB |
Output is correct |
9 |
Correct |
37 ms |
35576 KB |
Output is correct |
10 |
Correct |
39 ms |
35576 KB |
Output is correct |
11 |
Correct |
37 ms |
35576 KB |
Output is correct |
12 |
Correct |
34 ms |
35548 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
31 ms |
35576 KB |
Output is correct |
2 |
Correct |
31 ms |
35576 KB |
Output is correct |
3 |
Correct |
31 ms |
35576 KB |
Output is correct |
4 |
Correct |
37 ms |
35704 KB |
Output is correct |
5 |
Correct |
37 ms |
35576 KB |
Output is correct |
6 |
Correct |
38 ms |
35576 KB |
Output is correct |
7 |
Correct |
32 ms |
35576 KB |
Output is correct |
8 |
Correct |
37 ms |
35576 KB |
Output is correct |
9 |
Correct |
37 ms |
35576 KB |
Output is correct |
10 |
Correct |
39 ms |
35576 KB |
Output is correct |
11 |
Correct |
37 ms |
35576 KB |
Output is correct |
12 |
Correct |
34 ms |
35548 KB |
Output is correct |
13 |
Correct |
31 ms |
35556 KB |
Output is correct |
14 |
Correct |
32 ms |
35676 KB |
Output is correct |
15 |
Correct |
246 ms |
35704 KB |
Output is correct |
16 |
Correct |
33 ms |
35576 KB |
Output is correct |
17 |
Correct |
52 ms |
35576 KB |
Output is correct |
18 |
Correct |
82 ms |
35592 KB |
Output is correct |
19 |
Correct |
283 ms |
35824 KB |
Output is correct |
20 |
Correct |
223 ms |
35704 KB |
Output is correct |
21 |
Correct |
142 ms |
35832 KB |
Output is correct |
22 |
Correct |
159 ms |
35796 KB |
Output is correct |
23 |
Correct |
112 ms |
35836 KB |
Output is correct |
24 |
Correct |
367 ms |
35704 KB |
Output is correct |
25 |
Correct |
274 ms |
35704 KB |
Output is correct |
26 |
Correct |
319 ms |
35704 KB |
Output is correct |
27 |
Correct |
355 ms |
35832 KB |
Output is correct |