Pagini recente » Cod sursa (job #171851) | Cod sursa (job #3233684) | Cod sursa (job #156544) | Cod sursa (job #1001146) | Cod sursa (job #1511225)
#include <cstdio>
const unsigned Nmax = 17;
unsigned w[Nmax]; // w[i] = greutatea obiectului i
unsigned d[1 << Nmax]; // numarul de camioane pentru submultimea codificata
int main(void) {
freopen("zebughil.in", "r", stdin);
freopen("zebughil.out", "w", stdout);
unsigned T, n, g;
register unsigned i, j, x;
for (T = 0; T < 3; T++) {
scanf("%u%u", &n, &g);
for (i = 0; i < n; i++) {
scanf("%u", &w[i]);
}
for (i = 1; i < (1U << n); i++) {
// c[i] = c[i & -i] + c[(i - 1) & i] sparge cache-ul
x = 0;
j = 0;
while ((j < n) && (x <= g)) {
if ((i >> j) & 1) {
x += w[j];
}
j++;
}
if (x <= g) {
d[i] = 1;
} else {
d[i] = n;
for (j = (i - 1) & i; j > (i ^ j); j = (j - 1) & i) {
x = d[i ^ j] + d[j];
if (d[i] > x) {
d[i] = x;
}
}
}
}
printf("%u\n", d[(1 << n) - 1]);
}
fclose(stdin);
fclose(stdout);
return 0;
}