#include <stdio.h>
#include <string.h>
#define N 50
#define L 10000
#define MD 1000000007
int max(int a, int b) { return a > b ? a : b; }
unsigned int X;
int rand_() {
return (X *= 3) >> 1;
}
int vv[L + 1], ff[L + 1], gg[L + 1];
void init() {
int i;
ff[0] = gg[0] = 1;
for (i = 1; i <= L; i++) {
vv[i] = i == 1 ? 1 : (long long) vv[i - MD % i] * (MD / i + 1) % MD;
ff[i] = (long long) ff[i - 1] * i % MD;
gg[i] = (long long) gg[i - 1] * vv[i] % MD;
}
}
int choose(int n, int k) {
return k < 0 || k > n ? 0 : (long long) ff[n] * gg[k] % MD * gg[n - k] % MD;
}
void sort(int *aa, int l, int r) {
while (l < r) {
int i = l, j = l, k = r, a = aa[l + rand_() % (r - l)], tmp;
while (j < k)
if (aa[j] == a)
j++;
else if (aa[j] < a) {
tmp = aa[i], aa[i] = aa[j], aa[j] = tmp;
i++, j++;
} else {
k--;
tmp = aa[j], aa[j] = aa[k], aa[k] = tmp;
}
sort(aa, l, i);
l = k;
}
}
int main() {
static int rr[N], dp[N + 1][L + 1], dq[N + 1][L + 1];
int n, l, i, c, s, ans;
init();
scanf("%d%d", &n, &l);
for (i = 0; i < n; i++)
scanf("%d", &rr[i]), rr[i]--;
sort(rr, 0, n);
dp[0][0] = 1;
for (i = 0; i < n; i++) {
int r = rr[i];
for (c = 0; c <= n; c++)
memset(dq[c], 0, (l + 1) * sizeof *dq[c]);
for (c = 0; c <= n; c++)
for (s = 0; s <= l; s++) {
int x = dp[c][s];
if (x == 0)
continue;
dq[c + 1][s] = (dq[c + 1][s] + x) % MD;
if (c > 0 && s + r <= l)
dq[c][s + r] = (dq[c][s + r] + (long long) x * c * 2) % MD;
if (c >= 2 && s + r * 2 <= l)
dq[c - 1][s + r * 2] = (dq[c - 1][s + r * 2] + (long long) x * c * (c - 1)) % MD;
}
for (c = 0; c <= n; c++)
memcpy(dp[c], dq[c], (l + 1) * sizeof *dq[c]);
}
ans = 0;
for (s = 0; s <= l; s++)
ans = (ans + (long long) dp[1][s] * choose(l - s, n)) % MD;
printf("%d\n", ans);
return 0;
}
Compilation message
Main.c: In function 'main':
Main.c:57:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
57 | scanf("%d%d", &n, &l);
| ^~~~~~~~~~~~~~~~~~~~~
Main.c:59:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
59 | scanf("%d", &rr[i]), rr[i]--;
| ^~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
4372 KB |
Output is correct |
2 |
Correct |
1 ms |
716 KB |
Output is correct |
3 |
Correct |
2 ms |
1228 KB |
Output is correct |
4 |
Correct |
1 ms |
716 KB |
Output is correct |
5 |
Correct |
2 ms |
972 KB |
Output is correct |
6 |
Correct |
9 ms |
2668 KB |
Output is correct |
7 |
Correct |
15 ms |
2852 KB |
Output is correct |
8 |
Correct |
1 ms |
404 KB |
Output is correct |
9 |
Correct |
6 ms |
2004 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1176 KB |
Output is correct |
2 |
Correct |
1 ms |
588 KB |
Output is correct |
3 |
Correct |
4 ms |
1228 KB |
Output is correct |
4 |
Correct |
1 ms |
716 KB |
Output is correct |
5 |
Correct |
2 ms |
1228 KB |
Output is correct |
6 |
Correct |
1 ms |
588 KB |
Output is correct |
7 |
Correct |
2 ms |
1228 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
660 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
656 KB |
Output is correct |
2 |
Correct |
1 ms |
520 KB |
Output is correct |
3 |
Correct |
1 ms |
660 KB |
Output is correct |
4 |
Correct |
1 ms |
588 KB |
Output is correct |
5 |
Correct |
1 ms |
656 KB |
Output is correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
7 |
Correct |
2 ms |
716 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
588 KB |
Output is correct |
10 |
Correct |
0 ms |
408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
4372 KB |
Output is correct |
2 |
Correct |
1 ms |
716 KB |
Output is correct |
3 |
Correct |
2 ms |
1228 KB |
Output is correct |
4 |
Correct |
1 ms |
716 KB |
Output is correct |
5 |
Correct |
2 ms |
972 KB |
Output is correct |
6 |
Correct |
9 ms |
2668 KB |
Output is correct |
7 |
Correct |
15 ms |
2852 KB |
Output is correct |
8 |
Correct |
1 ms |
404 KB |
Output is correct |
9 |
Correct |
6 ms |
2004 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
2 ms |
1176 KB |
Output is correct |
12 |
Correct |
1 ms |
588 KB |
Output is correct |
13 |
Correct |
4 ms |
1228 KB |
Output is correct |
14 |
Correct |
1 ms |
716 KB |
Output is correct |
15 |
Correct |
2 ms |
1228 KB |
Output is correct |
16 |
Correct |
1 ms |
588 KB |
Output is correct |
17 |
Correct |
2 ms |
1228 KB |
Output is correct |
18 |
Correct |
1 ms |
460 KB |
Output is correct |
19 |
Correct |
1 ms |
660 KB |
Output is correct |
20 |
Correct |
1 ms |
460 KB |
Output is correct |
21 |
Correct |
1 ms |
656 KB |
Output is correct |
22 |
Correct |
1 ms |
520 KB |
Output is correct |
23 |
Correct |
1 ms |
660 KB |
Output is correct |
24 |
Correct |
1 ms |
588 KB |
Output is correct |
25 |
Correct |
1 ms |
656 KB |
Output is correct |
26 |
Correct |
1 ms |
460 KB |
Output is correct |
27 |
Correct |
2 ms |
716 KB |
Output is correct |
28 |
Correct |
1 ms |
460 KB |
Output is correct |
29 |
Correct |
1 ms |
588 KB |
Output is correct |
30 |
Correct |
0 ms |
408 KB |
Output is correct |
31 |
Correct |
34 ms |
4364 KB |
Output is correct |
32 |
Correct |
21 ms |
3408 KB |
Output is correct |
33 |
Correct |
34 ms |
4300 KB |
Output is correct |
34 |
Correct |
7 ms |
2124 KB |
Output is correct |
35 |
Correct |
42 ms |
4380 KB |
Output is correct |
36 |
Correct |
2 ms |
1228 KB |
Output is correct |
37 |
Correct |
36 ms |
4316 KB |
Output is correct |
38 |
Correct |
6 ms |
1440 KB |
Output is correct |
39 |
Correct |
41 ms |
4300 KB |
Output is correct |
40 |
Correct |
9 ms |
2636 KB |
Output is correct |
41 |
Correct |
32 ms |
4300 KB |
Output is correct |
42 |
Correct |
1 ms |
588 KB |
Output is correct |
43 |
Correct |
26 ms |
4300 KB |
Output is correct |
44 |
Correct |
4 ms |
1484 KB |
Output is correct |
45 |
Correct |
26 ms |
4300 KB |
Output is correct |
46 |
Correct |
1 ms |
588 KB |
Output is correct |
47 |
Correct |
8 ms |
2508 KB |
Output is correct |
48 |
Correct |
4 ms |
1356 KB |
Output is correct |
49 |
Correct |
1 ms |
876 KB |
Output is correct |
50 |
Correct |
0 ms |
460 KB |
Output is correct |