Problem C
Knapsack
Implement a solution to the classic knapsack problem. You are given a knapsack that can hold up to a certain weight (its capacity), and several items you may choose to put in the knapsack. Each item has a weight and a value. Choose a subset of the items (which could be all of them, or none of them) having the greatest value that fit into the knapsack (i.e. the sum of the weights of the items you choose must be less than or equal to the knapsack capacity).
Input
The input consists of between
Output
For each test case, output a line containing the number of
items chosen, followed by a line containing the indices of the
chosen items (the first item has index
Sample Input 1 | Sample Output 1 |
---|---|
5 3 1 5 10 5 100 5 6 4 5 4 4 3 3 2 2 1 |
1 2 3 1 2 3 |