#include <bits/stdc++.h>
using namespace std;
const int N = 355, p = 1e9 + 7;
using ll = long long;
int dp[N][N][2], C[N][N];
int n;
int sit(int man, int seat, bool good) {
if (man > n) return !seat && good;
if (dp[man][seat][good] != -1) return dp[man][seat][good];
int ans = 0;
for (int i = 0; i <= seat; ++i)
(ans += 1ll * sit(man + 1, seat - i, good || (i == man)) * C[seat][i] % p) %= p;
return dp[man][seat][good] = ans;
}
int main() {
memset(dp, -1, sizeof dp);
cin >> n;
for (int i = 0; i <= n; ++i) {
C[i][0] = 1;
for (int j = 1; j <= i; ++j)
C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % p;
}
cout << sit(1, n, false);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1236 KB |
Output is correct |
2 |
Correct |
1 ms |
1292 KB |
Output is correct |
3 |
Correct |
1 ms |
1288 KB |
Output is correct |
4 |
Correct |
1 ms |
1236 KB |
Output is correct |
5 |
Correct |
1 ms |
1236 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1236 KB |
Output is correct |
2 |
Correct |
1 ms |
1292 KB |
Output is correct |
3 |
Correct |
1 ms |
1288 KB |
Output is correct |
4 |
Correct |
1 ms |
1236 KB |
Output is correct |
5 |
Correct |
1 ms |
1236 KB |
Output is correct |
6 |
Correct |
2 ms |
1236 KB |
Output is correct |
7 |
Correct |
1 ms |
1292 KB |
Output is correct |
8 |
Correct |
1 ms |
1236 KB |
Output is correct |
9 |
Correct |
1 ms |
1236 KB |
Output is correct |
10 |
Correct |
1 ms |
1236 KB |
Output is correct |
11 |
Correct |
1 ms |
1292 KB |
Output is correct |
12 |
Correct |
1 ms |
1236 KB |
Output is correct |
13 |
Correct |
1 ms |
1236 KB |
Output is correct |
14 |
Correct |
1 ms |
1236 KB |
Output is correct |
15 |
Correct |
1 ms |
1236 KB |
Output is correct |
16 |
Correct |
1 ms |
1236 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1236 KB |
Output is correct |
2 |
Correct |
1 ms |
1292 KB |
Output is correct |
3 |
Correct |
1 ms |
1288 KB |
Output is correct |
4 |
Correct |
1 ms |
1236 KB |
Output is correct |
5 |
Correct |
1 ms |
1236 KB |
Output is correct |
6 |
Correct |
2 ms |
1236 KB |
Output is correct |
7 |
Correct |
1 ms |
1292 KB |
Output is correct |
8 |
Correct |
1 ms |
1236 KB |
Output is correct |
9 |
Correct |
1 ms |
1236 KB |
Output is correct |
10 |
Correct |
1 ms |
1236 KB |
Output is correct |
11 |
Correct |
1 ms |
1292 KB |
Output is correct |
12 |
Correct |
1 ms |
1236 KB |
Output is correct |
13 |
Correct |
1 ms |
1236 KB |
Output is correct |
14 |
Correct |
1 ms |
1236 KB |
Output is correct |
15 |
Correct |
1 ms |
1236 KB |
Output is correct |
16 |
Correct |
1 ms |
1236 KB |
Output is correct |
17 |
Correct |
249 ms |
1672 KB |
Output is correct |
18 |
Correct |
3 ms |
1364 KB |
Output is correct |
19 |
Correct |
53 ms |
1512 KB |
Output is correct |
20 |
Correct |
2 ms |
1236 KB |
Output is correct |
21 |
Correct |
335 ms |
1720 KB |
Output is correct |
22 |
Correct |
38 ms |
1492 KB |
Output is correct |
23 |
Correct |
4 ms |
1364 KB |
Output is correct |
24 |
Correct |
70 ms |
1548 KB |
Output is correct |
25 |
Correct |
54 ms |
1500 KB |
Output is correct |
26 |
Correct |
103 ms |
1492 KB |
Output is correct |
27 |
Correct |
477 ms |
1772 KB |
Output is correct |
28 |
Correct |
491 ms |
1772 KB |
Output is correct |
29 |
Correct |
482 ms |
1776 KB |
Output is correct |
30 |
Correct |
498 ms |
1748 KB |
Output is correct |
31 |
Correct |
503 ms |
1784 KB |
Output is correct |
32 |
Correct |
500 ms |
1784 KB |
Output is correct |
33 |
Correct |
498 ms |
1748 KB |
Output is correct |
34 |
Correct |
500 ms |
1784 KB |
Output is correct |
35 |
Correct |
514 ms |
1748 KB |
Output is correct |
36 |
Correct |
521 ms |
1784 KB |
Output is correct |
37 |
Correct |
519 ms |
1792 KB |
Output is correct |