zoukankan      html  css  js  c++  java
  • 01背包问题中递归产生所有可能组合

    运行结果

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

    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);
            
            
            
        }
    
    }
  • 相关阅读:
    TCP的初始cwnd和ssthresh
    C/C++ main
    PHP Function
    run bin
    PHP
    LAMP
    PHP MATH
    PHP array sort
    inline
    gcc g++
  • 原文地址:https://www.cnblogs.com/hansongjiang/p/3615208.html
Copyright © 2011-2022 走看看