标签:
public class Zi { static int[] w = {1,2,2,4,5,6,6}; static int[] x = new int[w.length]; static int m = 10; static int sum=0; public static void main(String[] args) { for(int i=0;i<w.length;i++){ sum+=w[i]; } Sumofsub(0, 0, sum); } public static void Sumofsub(int s,int k,int r){ x[k]=1; if(s+w[k]==m){ for(int j=0;j<w.length;j++){ System.out.print(x[j]+" "); } System.out.println(); }else if(s+w[k]+w[k+1]<=m){ Sumofsub(s+w[k],k+1,r-w[k]); } if(s+r-w[k]>=m&&s+w[k+1]<=m){ x[k]=0; Sumofsub(s,k+1,r-w[k]); } } }
标签:
原文地址:http://www.cnblogs.com/mao-19/p/5347734.html