标签:
1 public boolean PackageProblem(int[] arr,int start,int left,int target) 2 { 3 if(arr.length==0) 4 { 5 System.out.println("no Answer"); 6 return false; 7 } 8 if(start==arr.length) 9 { 10 int[] tempArr=new int[arr.length-1]; 11 System.arraycopy(arr, 1, tempArr, 0, arr.length-1);15 return PackageProblem(tempArr, 0, target, target); 16 } 17 else if(arr[start]>left) 18 { 19 return PackageProblem(arr, start+1, left, target); 20 } 21 else if(arr[start]==left) 22 { 23 System.out.println("yes has answer"); 24 return true; 25 } 26 else{ 27 return PackageProblem(arr, start+1, left-arr[start], target); 28 } 29 30 }
int[] arr={11,10,8,7,5,3};
int target=21;
但是这个数组要是从大到小排好的?
int[] arr={11,8,7,5,3,10};就不行
标签:
原文地址:http://www.cnblogs.com/sweetculiji/p/4292194.html