#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);
#define s second
#define f first
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll LOGN = 18;
const ll INF = 1e15;
const ll MAXN = 400;
ll expo(ll a, ll b) {
ll res = 1;
while (b) {
if (b & 1)
res = (res * a) % MOD;
a = (a * a) % MOD;
b /= 2;
}
return res;
}
ll dp[MAXN][MAXN][2];
ll fact[5 * MAXN], inv[5 * MAXN];
ll nCr(ll n, ll r) {
return ((fact[n] * inv[r]) % MOD * inv[n-r]) % MOD;
}
int main() {
fast
fact[0] = inv[0] = 1;
for (ll i = 1; i < 5*MAXN; i++) {
fact[i] = (fact[i-1] * i) % MOD;
inv[i] = expo(fact[i], MOD - 2);
}
int N;
cin >> N;
dp[0][0][0] = 1;
for (int i = 1; i <= N; i++) {
for (int last = 0; last <= N; last++) {
for (int now = last; now <= N; now++) {
int rem = N - last;
ll choose = nCr(rem, now - last);
if (now - last != i)
dp[i][now][0] = (dp[i][now][0] + (dp[i-1][last][0] * choose) % MOD) % MOD;
if (i == now - last)
dp[i][now][1] = (dp[i][now][1] + ((dp[i-1][last][0] + dp[i-1][last][1]) * choose) % MOD) % MOD;
else
dp[i][now][1] = (dp[i][now][1] + (dp[i-1][last][1] * choose) % MOD) % MOD;
}
}
}
cout << dp[N][N][1] << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
492 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
496 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
492 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
496 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
110 ms |
2192 KB |
Output is correct |
18 |
Correct |
1 ms |
600 KB |
Output is correct |
19 |
Correct |
23 ms |
1368 KB |
Output is correct |
20 |
Correct |
1 ms |
604 KB |
Output is correct |
21 |
Correct |
155 ms |
2152 KB |
Output is correct |
22 |
Correct |
17 ms |
1168 KB |
Output is correct |
23 |
Correct |
2 ms |
604 KB |
Output is correct |
24 |
Correct |
31 ms |
1380 KB |
Output is correct |
25 |
Correct |
22 ms |
1372 KB |
Output is correct |
26 |
Correct |
42 ms |
1624 KB |
Output is correct |
27 |
Correct |
203 ms |
2388 KB |
Output is correct |
28 |
Correct |
209 ms |
2484 KB |
Output is correct |
29 |
Correct |
206 ms |
2504 KB |
Output is correct |
30 |
Correct |
209 ms |
2644 KB |
Output is correct |
31 |
Correct |
215 ms |
2404 KB |
Output is correct |
32 |
Correct |
212 ms |
2612 KB |
Output is correct |
33 |
Correct |
215 ms |
2640 KB |
Output is correct |
34 |
Correct |
217 ms |
2456 KB |
Output is correct |
35 |
Correct |
222 ms |
2484 KB |
Output is correct |
36 |
Correct |
226 ms |
2536 KB |
Output is correct |
37 |
Correct |
222 ms |
2420 KB |
Output is correct |