• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            Zero Lee的專欄

            一組數的全排列和組合程序實現

            顯示一組數的全排列和組合程序:
             1 void print(const std::vector<int>& s)
             2 {
             3     static int n = 1;
             4     printf("%d:", n++);
             5     printf("[");
             6     for (int i = 0; i < s.size(); i++)
             7         printf(" %d ", s[i]);
             8     printf("]\n");
             9 }
            10 
            11 void permutation(std::vector<int>& v, int beg, int end)
            12 {
            13     if (beg > end) {
            14         print(v);
            15         return;
            16     }
            17     for (int i = beg; i <= end; i++) {
            18         std::swap(v[i], v[beg]);
            19         permutation(v, beg+1, end); // pleate note, here always beg+1, not i+1
            20         std::swap(v[i], v[beg]);
            21     }
            22 }
            23 
            24 void pm(std::vector<int>& v)
            25 {
            26     std::copy(v.begin(), v.end(), std::ostream_iterator<int>(std::cout, " "));
            27     printf("\nfull permulation are:\n");
            28     permutation(v, 0, v.size()-1);
            29 }
            30 
            31 void print(const std::vector<int>& v, int beg, int end)
            32 {
            33     static int n = 1;
            34     printf("%d:", n++);
            35     printf("[");
            36     std::copy(v.begin()+beg, v.begin()+end+1, std::ostream_iterator<int>(std::cout, " "));
            37     printf("]\n");
            38 }
            39 
            40 void fullcombination(std::vector<int>& v)
            41 {
            42     printf("
            full combination are:\n");
            43     for (unsigned int i = 0; i < v.size(); i++) {
            44         print(v, i, i);
            45         for (unsigned int j = i+1; j < v.size(); j++) {
            46             for (int k = 0; k < v.size()-j; k++) {
            47                 std::swap(v[j+k], v[j]);
            48                 print(v, i, j);
            49                 std::swap(v[j+k], v[j]);
            50             }
            51         }
            52     }
            53 }
            54 

            posted on 2011-10-19 09:34 Zero Lee 閱讀(706) 評論(0)  編輯 收藏 引用 所屬分類: Data structure and algorithms

            久久久免费精品re6| 久久综合综合久久97色| 久久九色综合九色99伊人| 久久91精品久久91综合| 久久久久久久久久久久中文字幕| 一级女性全黄久久生活片免费| 久久国产热这里只有精品| 久久精品无码av| 久久亚洲精品无码观看不卡| 欧美精品福利视频一区二区三区久久久精品| 久久久91精品国产一区二区三区| 国产精品女同久久久久电影院| 国产精品国色综合久久| 国产午夜福利精品久久2021| 91久久精一区二区三区大全| 97r久久精品国产99国产精| 99久久精品无码一区二区毛片| 大美女久久久久久j久久| 久久精品国产精品亚洲下载| 久久天天躁狠狠躁夜夜av浪潮| 午夜精品久久久久久| 久久精品国产亚洲AV不卡| 久久精品国产久精国产一老狼| 国内精品久久久久影院薰衣草 | 久久精品无码专区免费青青| 99国产精品久久久久久久成人热| 日本福利片国产午夜久久| 狠狠精品久久久无码中文字幕| 欧美性猛交xxxx免费看久久久| 久久精品国产亚洲av麻豆蜜芽| 久久久久亚洲AV无码麻豆| 久久久久久久综合日本亚洲| 久久精品亚洲欧美日韩久久| 2021国产精品午夜久久| 97久久超碰成人精品网站| 色婷婷综合久久久久中文字幕| 婷婷伊人久久大香线蕉AV| 精品无码人妻久久久久久| 无码AV中文字幕久久专区| 久久精品无码av| 99久久国语露脸精品国产|