• <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 閱讀(697) 評論(0)  編輯 收藏 引用 所屬分類: Data structure and algorithms

            久久国产精品99精品国产| 精品久久久久久国产潘金莲| 一本一道久久a久久精品综合| 国产精品久久久久久久久久影院| 亚洲精品乱码久久久久久自慰 | 国产福利电影一区二区三区久久老子无码午夜伦不 | 久久久久久久久久久精品尤物| 国产精品久久久久9999高清| 久久国产AVJUST麻豆| 久久99精品国产99久久| 性做久久久久久久久浪潮| 亚洲国产精品久久久久婷婷软件 | 日产精品99久久久久久| 久久人人爽人爽人人爽av| 久久国产精品99国产精| 久久久久青草线蕉综合超碰| 91久久福利国产成人精品| 性高湖久久久久久久久| 亚洲欧洲久久久精品| 99精品伊人久久久大香线蕉| 中文精品久久久久人妻不卡| 久久九色综合九色99伊人| 久久不射电影网| 久久亚洲春色中文字幕久久久| 亚洲国产香蕉人人爽成AV片久久| 免费国产99久久久香蕉| www.久久精品| 久久久青草青青亚洲国产免观| 久久精品亚洲日本波多野结衣 | 奇米综合四色77777久久| 久久亚洲电影| 国产精久久一区二区三区| 国产精品久久久久9999高清| 97久久国产亚洲精品超碰热| 久久综合国产乱子伦精品免费| 97久久婷婷五月综合色d啪蜜芽| 欧美伊人久久大香线蕉综合69| 久久精品夜色噜噜亚洲A∨| 久久久久亚洲精品无码网址| 午夜视频久久久久一区| 久久无码精品一区二区三区|