/**
* @author Think
* 给定整数a1,a2,a3,a4…,判断是否可以从中选出若干数,使他们的和恰好为K
*/
public class 深度优先算法 {
//n=4,a={1,2,4,7};k=13;
public static int n=4;
public static int [] a={1,2,4,7};
public static int k=13;
public static void main(String[] args) {
// findByFor(a,k);
boolean boo=findByDeep(0,0);
System.out.println("boo"+boo);
}
/**
* @param a
* @param k
* 1、 1 2 、1 2 4 、 1 2 4 7
2 、2 4、 2 4 7
4 、4 7、
7
*通过for循环来写的
*
*/
public static void findByFor(int[] a,int k){
int sum=0;
for(int i=0;i<a.length;i++){
for(int j=i;j<a.length;j++){
// System.out.println("a[j]"+a[j]);
sum+=a[j];
// System.out.println("sum"+sum);
if(sum==k){
System.out.println("true");
return;
}
}
s