首页 > 其他 > 详细

01背包问题中递归产生所有可能组合

时间:2014-03-21 11:25:35      阅读:480      评论:0      收藏:0      [点我收藏+]

 

运行结果

0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
1010
1011
1100
1101
1110
1111

bubuko.com,布布扣
package huawei;

public class 零一问题 {
    public static void zuhe(int res[],int index,int len)
    {
        if(index==len)
        {
            StringBuffer sfb=new StringBuffer();
            for(int i=0;i<len;i++)
            {
                sfb.append(res[i]);
                
            }
            System.out.println(sfb.toString());
            sfb=null;
        }
        else
        {
            for(int i=0;i<=1;i++)
            {
                res[index]=i;
                zuhe(res,index+1,len);
                
                
            }
            
            
            
        }
        
    }
    public static void main(String[] args)
    {
        int a[]=new int[8];
    
    
        zuhe(a,0,8);
        
        
        
    }

}
bubuko.com,布布扣

01背包问题中递归产生所有可能组合,布布扣,bubuko.com

01背包问题中递归产生所有可能组合

原文:http://www.cnblogs.com/hansongjiang/p/3615208.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!