日期:2014-05-20 浏览次数:20630 次
public static void main(String[] args) {
int[] a = { 1,3,4,5,8,7,8,10,34};
for (int n = 1; n <= a.length; n++) {
int[] b = new int[n];
submit(a, 0, 0, n, b);
}
}
public static void submit(int[] a, int c, int i, int n, int[] b) {
for (int j = c; j < a.length - (n - 1); j++) {
int sum = 0 ;
b[i] = a[j];
if (n == 1) {
//System.out.println();
for(int k=0;k<b.length;k++){
sum+= b[k];
}
if(sum==25){//在这里判断
System.out.println(Arrays.toString(b));
}
} else {
n--;
i++;
submit(a, j + 1, i, n, b);
n++;
i--;
}
}
}
import java.util.LinkedList;
import java.util.List;