#include <bits/stdc++.h>
using namespace std;
constexpr int NMAX = 355;
constexpr int MOD = 1e9 + 7;
int N;
int dp_not_Good[NMAX][NMAX];
int dp_Total[NMAX][NMAX];
int Comb[2*NMAX][2*NMAX];
void Read () {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> N;
}
void Precalculare () {
Comb[0][0] = 1;
for (int i = 1; i <= 2*N; ++ i ) {
Comb[i][0] = 1;
for (int j = 1; j <= i; ++ j )
Comb[i][j] = (Comb[i-1][j-1] + Comb[i-1][j]) % MOD;
}
}
void Solve () {
dp_not_Good[0][0] = 1;
dp_Total[0][0] = 1;
for (int i = 1; i <= N; ++ i ) {
for (int j = 0; j <= N; ++ j ) {
for (int cnt = 0; cnt <= j; ++ cnt ) {
if (cnt == i) continue;
dp_not_Good[i][j] = (1LL * dp_not_Good[i][j] + 1LL * Comb[j][cnt] * dp_not_Good[i-1][j-cnt]) % MOD;
}
for (int cnt = 0; cnt <= j; ++ cnt )
dp_Total[i][j] = (1LL * dp_Total[i][j] + 1LL * Comb[j][cnt] * dp_Total[i-1][j-cnt]) % MOD;
}
}
cout << (dp_Total[N][N] - dp_not_Good[N][N] + MOD) % MOD << '\n';
}
int main () {
Read();
Precalculare();
Solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
328 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
324 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
328 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
324 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
328 KB |
Output is correct |
7 |
Correct |
1 ms |
360 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
460 KB |
Output is correct |
13 |
Correct |
1 ms |
464 KB |
Output is correct |
14 |
Correct |
1 ms |
464 KB |
Output is correct |
15 |
Correct |
1 ms |
464 KB |
Output is correct |
16 |
Correct |
1 ms |
464 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
328 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
324 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
328 KB |
Output is correct |
7 |
Correct |
1 ms |
360 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
460 KB |
Output is correct |
13 |
Correct |
1 ms |
464 KB |
Output is correct |
14 |
Correct |
1 ms |
464 KB |
Output is correct |
15 |
Correct |
1 ms |
464 KB |
Output is correct |
16 |
Correct |
1 ms |
464 KB |
Output is correct |
17 |
Correct |
116 ms |
2520 KB |
Output is correct |
18 |
Correct |
1 ms |
720 KB |
Output is correct |
19 |
Correct |
27 ms |
1628 KB |
Output is correct |
20 |
Correct |
1 ms |
464 KB |
Output is correct |
21 |
Correct |
164 ms |
2840 KB |
Output is correct |
22 |
Correct |
19 ms |
1428 KB |
Output is correct |
23 |
Correct |
2 ms |
840 KB |
Output is correct |
24 |
Correct |
32 ms |
1768 KB |
Output is correct |
25 |
Correct |
24 ms |
1552 KB |
Output is correct |
26 |
Correct |
46 ms |
1952 KB |
Output is correct |
27 |
Correct |
226 ms |
3080 KB |
Output is correct |
28 |
Correct |
230 ms |
3144 KB |
Output is correct |
29 |
Correct |
229 ms |
3148 KB |
Output is correct |
30 |
Correct |
250 ms |
3180 KB |
Output is correct |
31 |
Correct |
246 ms |
3136 KB |
Output is correct |
32 |
Correct |
237 ms |
3168 KB |
Output is correct |
33 |
Correct |
234 ms |
3184 KB |
Output is correct |
34 |
Correct |
257 ms |
3180 KB |
Output is correct |
35 |
Correct |
239 ms |
3224 KB |
Output is correct |
36 |
Correct |
263 ms |
3144 KB |
Output is correct |
37 |
Correct |
241 ms |
3144 KB |
Output is correct |