#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 3018;
const int MOD = 1e9 + 7;
//#define debug(...) fprintf(stderr, __VA_ARGS__)
#define debug(...)
#define fi first
#define se second
#define all(v) (v).begin(), (v).end()
#define fillchar(a, s) memset((a), (s), sizeof(a))
void addeq (int &x, int y) {
x += y;
if (x >= MOD) {
x -= MOD;
}
}
int add (int x, int y) {
addeq(x, y);
return x;
}
int mult (int x, int y) {
return ll(x) * y % MOD;
}
int mult (int x, int y, int z) {
return mult(mult(x, y), z);
}
int mult (int x, int y, int z, int w) {
return mult(mult(x, y), mult(z, w));
}
int cho2[MAXN];
void precomp() {
for (int i = 2; i < MAXN; i++) {
cho2[i] = i * (i - 1) / 2;
}
}
int N, M;
int dp[MAXN][MAXN];
int psum1[MAXN][MAXN], psum2[MAXN][MAXN], psum3[MAXN][MAXN];
void compute_psum (int j) {
int p = 0;
for (int i = 0; i <= N; i++) {
addeq(p, mult(4, j + 1, dp[i][j]));
psum1[i][j] = p;
}
p = 0;
for (int i = 0; i <= N; i++) {
addeq(p, mult(cho2[j + 2], dp[i][j]));
psum2[i][j] = p;
}
p = 0;
for (int i = 0; i <= N; i++) {
addeq(p, mult(j + 1, i + 1, dp[i][j]));
psum3[i][j] = p;
}
}
int main() {
precomp();
scanf("%d %d", &N, &M);
for (int i = 0; i < MAXN; i++) {
for (int j = 0; j < MAXN; j++) {
dp[i][j] = 1;
}
}
compute_psum(0);
for (int j = 1; j <= M; j++) {
for (int i = 1; i <= N; i++) {
addeq(dp[i][j], psum1[i - 1][j - 1]);
if (j > 1) {
addeq(dp[i][j], psum2[i - 1][j - 2]);
}
if (i > 1) {
addeq(dp[i][j], psum3[i - 2][j - 1]);
}
}
compute_psum(j);
}
printf("%d\n", add(dp[N][M], MOD - 1));
}
Compilation message
tents.cpp: In function 'int main()':
tents.cpp:76:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &N, &M);
~~~~~^~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
43 ms |
35960 KB |
Output is correct |
2 |
Correct |
39 ms |
36068 KB |
Output is correct |
3 |
Correct |
45 ms |
36784 KB |
Output is correct |
4 |
Correct |
49 ms |
38696 KB |
Output is correct |
5 |
Correct |
42 ms |
38696 KB |
Output is correct |
6 |
Correct |
44 ms |
39180 KB |
Output is correct |
7 |
Correct |
44 ms |
39180 KB |
Output is correct |
8 |
Correct |
47 ms |
39444 KB |
Output is correct |
9 |
Correct |
40 ms |
39444 KB |
Output is correct |
10 |
Correct |
47 ms |
40168 KB |
Output is correct |
11 |
Correct |
33 ms |
40168 KB |
Output is correct |
12 |
Correct |
40 ms |
40944 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
43 ms |
35960 KB |
Output is correct |
2 |
Correct |
39 ms |
36068 KB |
Output is correct |
3 |
Correct |
45 ms |
36784 KB |
Output is correct |
4 |
Correct |
49 ms |
38696 KB |
Output is correct |
5 |
Correct |
42 ms |
38696 KB |
Output is correct |
6 |
Correct |
44 ms |
39180 KB |
Output is correct |
7 |
Correct |
44 ms |
39180 KB |
Output is correct |
8 |
Correct |
47 ms |
39444 KB |
Output is correct |
9 |
Correct |
40 ms |
39444 KB |
Output is correct |
10 |
Correct |
47 ms |
40168 KB |
Output is correct |
11 |
Correct |
33 ms |
40168 KB |
Output is correct |
12 |
Correct |
40 ms |
40944 KB |
Output is correct |
13 |
Correct |
32 ms |
40944 KB |
Output is correct |
14 |
Correct |
57 ms |
64120 KB |
Output is correct |
15 |
Correct |
953 ms |
134416 KB |
Output is correct |
16 |
Correct |
56 ms |
134416 KB |
Output is correct |
17 |
Correct |
164 ms |
134416 KB |
Output is correct |
18 |
Correct |
240 ms |
134416 KB |
Output is correct |
19 |
Correct |
1012 ms |
139612 KB |
Output is correct |
20 |
Correct |
822 ms |
139612 KB |
Output is correct |
21 |
Correct |
568 ms |
139612 KB |
Output is correct |
22 |
Correct |
518 ms |
139612 KB |
Output is correct |
23 |
Correct |
359 ms |
139612 KB |
Output is correct |
24 |
Correct |
1456 ms |
142880 KB |
Output is correct |
25 |
Correct |
1083 ms |
142880 KB |
Output is correct |
26 |
Correct |
1187 ms |
142880 KB |
Output is correct |
27 |
Correct |
1360 ms |
142880 KB |
Output is correct |