Anonymous user
Subset sum problem: Difference between revisions
→{{header|C}}: Call it a set not path
(→{{header|C}}: shorten the example, to show all the zero sum subsets, you can kill the process if you got all you need from it. and its easier to follow without the bit math which doesn't change the time complexity anyway.) |
(→{{header|C}}: Call it a set not path) |
||
Line 207:
int n = sizeof (items) / sizeof (item_t);
int *
void subsum (int i, int weight) {
Line 213:
if (i && !weight) {
for (j = 0; j < i; j++) {
item_t item = items[
printf("%s%s", j ? " " : "", items[
}
printf("\n");
}
for (j = i ?
subsum(i + 1, weight + items[j].weight);
}
Line 225:
int main () {
subsum(0, 0);
return 0;
|