#include <bits/stdc++.h>
using namespace std;
typedef long long llint;
const int maxn = 400;
const llint mod = 1e9+7;
int n;
llint dp[maxn][maxn][3];
llint fac[maxn];
llint chos[maxn][maxn];
llint f(int x, int y, bool flag) {
if (x == n + 1) {
if (y == 0) return flag;
else return 0;
}
llint &ret = dp[x][y][flag];
if (ret != -1) return ret;
ret = 0;
for (int i = 0; i <= y; i++) {
ret += chos[y][i] * f(x + 1, y - i, flag || (i == x));
ret %= mod;
}
return ret;
}
llint pot(llint a, llint b) {
if (b == 0) return 1;
else if (b % 2 == 1) return (a * pot(a, b - 1)) % mod;
else {
llint out = pot(a, b / 2);
return (out * out) % mod;
}
}
llint inv(llint x) {
return pot(x, mod - 2);
}
llint choose(int a, int b) {
llint out = fac[a];
out *= inv(fac[b]), out %= mod;
out *= inv(fac[a - b]), out %= mod;
return out;
}
int main() {
memset(dp, -1, sizeof dp);
scanf("%d", &n);
fac[0] = 1;
for (int i = 1; i <= n; i++)
fac[i] = fac[i - 1] * i, fac[i] %= mod;
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= i; j++) {
chos[i][j] = choose(i, j);
}
}
printf("%lld\n", f(1, n, false));
return 0;
}
Compilation message
zapina.cpp: In function 'int main()':
zapina.cpp:53:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
~~~~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
4096 KB |
Output is correct |
2 |
Correct |
6 ms |
4096 KB |
Output is correct |
3 |
Correct |
6 ms |
4096 KB |
Output is correct |
4 |
Correct |
6 ms |
4096 KB |
Output is correct |
5 |
Correct |
6 ms |
4096 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
4096 KB |
Output is correct |
2 |
Correct |
6 ms |
4096 KB |
Output is correct |
3 |
Correct |
6 ms |
4096 KB |
Output is correct |
4 |
Correct |
6 ms |
4096 KB |
Output is correct |
5 |
Correct |
6 ms |
4096 KB |
Output is correct |
6 |
Correct |
6 ms |
4096 KB |
Output is correct |
7 |
Correct |
6 ms |
4096 KB |
Output is correct |
8 |
Correct |
6 ms |
4224 KB |
Output is correct |
9 |
Correct |
6 ms |
4096 KB |
Output is correct |
10 |
Correct |
7 ms |
4096 KB |
Output is correct |
11 |
Correct |
6 ms |
4224 KB |
Output is correct |
12 |
Correct |
6 ms |
4096 KB |
Output is correct |
13 |
Correct |
7 ms |
4096 KB |
Output is correct |
14 |
Correct |
7 ms |
4224 KB |
Output is correct |
15 |
Correct |
7 ms |
4096 KB |
Output is correct |
16 |
Correct |
7 ms |
4224 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
4096 KB |
Output is correct |
2 |
Correct |
6 ms |
4096 KB |
Output is correct |
3 |
Correct |
6 ms |
4096 KB |
Output is correct |
4 |
Correct |
6 ms |
4096 KB |
Output is correct |
5 |
Correct |
6 ms |
4096 KB |
Output is correct |
6 |
Correct |
6 ms |
4096 KB |
Output is correct |
7 |
Correct |
6 ms |
4096 KB |
Output is correct |
8 |
Correct |
6 ms |
4224 KB |
Output is correct |
9 |
Correct |
6 ms |
4096 KB |
Output is correct |
10 |
Correct |
7 ms |
4096 KB |
Output is correct |
11 |
Correct |
6 ms |
4224 KB |
Output is correct |
12 |
Correct |
6 ms |
4096 KB |
Output is correct |
13 |
Correct |
7 ms |
4096 KB |
Output is correct |
14 |
Correct |
7 ms |
4224 KB |
Output is correct |
15 |
Correct |
7 ms |
4096 KB |
Output is correct |
16 |
Correct |
7 ms |
4224 KB |
Output is correct |
17 |
Correct |
202 ms |
5008 KB |
Output is correct |
18 |
Correct |
9 ms |
4224 KB |
Output is correct |
19 |
Correct |
48 ms |
4608 KB |
Output is correct |
20 |
Correct |
6 ms |
4096 KB |
Output is correct |
21 |
Correct |
242 ms |
5112 KB |
Output is correct |
22 |
Correct |
37 ms |
4480 KB |
Output is correct |
23 |
Correct |
9 ms |
4224 KB |
Output is correct |
24 |
Correct |
61 ms |
4608 KB |
Output is correct |
25 |
Correct |
44 ms |
4608 KB |
Output is correct |
26 |
Correct |
79 ms |
4736 KB |
Output is correct |
27 |
Correct |
344 ms |
5344 KB |
Output is correct |
28 |
Correct |
342 ms |
5240 KB |
Output is correct |
29 |
Correct |
344 ms |
5372 KB |
Output is correct |
30 |
Correct |
348 ms |
5116 KB |
Output is correct |
31 |
Correct |
359 ms |
5244 KB |
Output is correct |
32 |
Correct |
354 ms |
5240 KB |
Output is correct |
33 |
Correct |
363 ms |
5244 KB |
Output is correct |
34 |
Correct |
362 ms |
5240 KB |
Output is correct |
35 |
Correct |
368 ms |
5368 KB |
Output is correct |
36 |
Correct |
369 ms |
5248 KB |
Output is correct |
37 |
Correct |
382 ms |
5368 KB |
Output is correct |