<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    不重復的排列組合示例

    昨天看到個帖子, 然后想了想寫出一段程序來.  有空該補補排列組合的知識了.

     1 /**
     2  * 各字符不重復的組合, 組合數小于等于最大可能性(否則就重復了).
     3  * 
     4  * @author scud(飛云)
     5  */
     6 public class ShortCombineTest
     7 {
     8     static int count = 0;
     9 
    10     public static void main(String[] args)
    11     {
    12         String s = "123456"//all items content
    13         int howmany = 3//how many object
    14 
    15         char[] c = s.toCharArray();
    16         char[] dest = new char[howmany];
    17 
    18         combine(c, dest, howmany, s.length(), 0);
    19 
    20         System.out.println("max combine:" + count);
    21     }
    22 
    23     public static void combine(char[] array, char[] dest, int howmany, int maxitem, int index)
    24     {
    25         //break & end
    26         if (index == howmany)
    27         {
    28             System.out.println(dest);
    29             count++;
    30             return;
    31         }
    32 
    33         while(array.length>0)
    34         {
    35             dest[index] = array[0];
    36             char[] nextarray = getLeftChar(array, 0);
    37             array = nextarray;
    38             combine(nextarray, dest, howmany, maxitem, index + 1);
    39         }
    40     }
    41 
    42     public static char[] getLeftChar(char[] c, int index)
    43     {
    44         char[] left = new char[c.length - 1];
    45 
    46         for (int i = 0, j = 0; i < c.length; i++)
    47         {
    48             if (i != index)
    49             {
    50                 left[j] = c[i];
    51                 j++;
    52             }
    53         }
    54 
    55         return left;
    56     }
    57 
    58 
    59 }
    60 


    posted on 2010-07-29 09:55 Scud(飛云小俠) 閱讀(440) 評論(0)  編輯  收藏 所屬分類: Java

    <2010年7月>
    27282930123
    45678910
    11121314151617
    18192021222324
    25262728293031
    1234567

    導航

    統計

    公告

    文章發布許可
    創造共用協議:署名,非商業,保持一致

    我的郵件
    cnscud # gmail


    常用鏈接

    留言簿(15)

    隨筆分類(113)

    隨筆檔案(103)

    相冊

    友情鏈接

    技術網站

    搜索

    積分與排名

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 黑人精品videos亚洲人| 亚洲www77777| 亚洲综合中文字幕无线码| 亚洲经典千人经典日产| 成年女人毛片免费视频| 国产成人无码综合亚洲日韩 | 亚洲精品视频免费| 亚洲五月六月丁香激情| 无码国产精品一区二区免费式芒果 | 日韩少妇内射免费播放| 亚洲电影日韩精品 | 亚洲第一区精品观看| 一级毛片免费全部播放| 久久久久久国产精品免费免费| 亚洲av片不卡无码久久| 在线观看特色大片免费网站| 四虎影视永久免费观看| 亚洲特级aaaaaa毛片| 成年女人A毛片免费视频| 青青草原亚洲视频| 免费女人高潮流视频在线观看| 亚洲日韩中文字幕| 叮咚影视在线观看免费完整版| 亚洲三级电影网址| 久久不见久久见中文字幕免费| 国产成人不卡亚洲精品91| 亚洲日韩欧洲乱码AV夜夜摸| 亚洲AV网一区二区三区| 亚洲高清免费在线观看| 亚洲色欲啪啪久久WWW综合网| 亚洲国产成人精品女人久久久| 免费国产成人午夜在线观看| 亚洲校园春色另类激情| 国产又粗又猛又爽又黄的免费视频| 精品国产呦系列在线观看免费| 亚洲av片一区二区三区| 国产成人AV片无码免费| 亚洲AV午夜成人片| 成人毛片18女人毛片免费96| 国产一级a毛一级a看免费人娇| 天堂亚洲国产中文在线|