This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |