标签:string oid int 剩余空间 next 输出 print input blog
1 import java.math.BigInteger; 2 import java.util.Arrays; 3 import java.util.Scanner; 4 5 6 public class Main { 7 static int n; 8 static int[] a; 9 static int mix = 200000; 10 public static void main(String[] args) { 11 Scanner input = new Scanner(System.in); 12 int sum = input.nextInt(); 13 n = input.nextInt(); 14 a = new int[n]; 15 for(int i=0;i<n;i++){ 16 a[i] = input.nextInt(); 17 } 18 f(sum,0); 19 System.out.println(mix); 20 21 } 22 public static int f(int sum,int i){ 23 if(sum<0) return -1; 24 if(i==n) {if(mix>sum) mix = sum;} 25 for(int j=i;j<n;j++){ 26 if(f(sum-a[j],j+1)==-1){ 27 if(mix>sum) mix = sum; 28 } 29 } 30 return sum; 31 32 33 34 35 } 36 }
标签:string oid int 剩余空间 next 输出 print input blog
原文地址:http://www.cnblogs.com/lolybj/p/6623516.html