Problem Description
There is a box with a volume of V (positive integer, 0<=v<=20000), and n items (0<n<=30), each with a volume (positive integer).
Requires n items, any number of boxes in the box, so that the remaining space of the box is minimal. Input format first behavior an integer representing the box capacity;
The second act is an integer that indicates that there are n items;
Next n rows, an integer per line represents the respective volume of the N items. An integer in the output format that represents the remaining space of the box.
Sample ExampleInput
24
6
8
3
12
7
9
7 Sample Output 0
1 ImportJava.math.BigInteger;2 Importjava.util.Arrays;3 ImportJava.util.Scanner;4 5 6 Public classMain {7 Static intN;8 Static int[] A;9 Static intMix = 200000;Ten Public Static voidMain (string[] args) { OneScanner input =NewScanner (system.in); A intsum =input.nextint (); -n =input.nextint (); -A =New int[n]; the for(inti=0;i<n;i++){ -A[i] =input.nextint (); - } -F (sum,0); + System.out.println (mix); - + } A Public Static intFintSuminti) { at if(sum<0)return-1; - if(i==n) {if(mix>sum) Mix =sum;} - for(intj=i;j<n;j++){ - if(f (sum-a[j],j+1) ==-1){ - if(mix>sum) Mix =sum; - } in } - returnsum; to + - the * } $}
Algorithm Training Boxing problem