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

            国产激情久久久久影院小草| 亚洲国产精品无码久久久久久曰 | 中文字幕无码av激情不卡久久| 久久无码人妻精品一区二区三区 | 色偷偷偷久久伊人大杳蕉| 欧美大香线蕉线伊人久久| 国产国产成人久久精品| 欧美日韩久久中文字幕| 久久精品国产亚洲av麻豆色欲| 日本道色综合久久影院| 一本色道久久综合亚洲精品| 国产精品对白刺激久久久| 亚洲?V乱码久久精品蜜桃| 国产精品一区二区久久不卡| 久久人妻少妇嫩草AV蜜桃| 亚洲av日韩精品久久久久久a | 亚洲αv久久久噜噜噜噜噜| 久久中文娱乐网| 欧美精品久久久久久久自慰| 久久亚洲AV永久无码精品| 国产成人久久精品激情| 久久久久国产精品嫩草影院| 久久久久人妻一区精品| 嫩草影院久久国产精品| 精品久久香蕉国产线看观看亚洲| 久久精品视频一| 亚洲国产成人精品91久久久 | 久久人人爽人人爽人人片AV东京热 | 国产精品无码久久久久| 99久久成人国产精品免费| 久久w5ww成w人免费| 久久精品国产AV一区二区三区| 香蕉aa三级久久毛片| 综合久久精品色| 亚洲国产日韩综合久久精品| 日日狠狠久久偷偷色综合96蜜桃| 狠狠人妻久久久久久综合蜜桃| 成人a毛片久久免费播放| 午夜不卡888久久| 久久99精品国产麻豆不卡| 久久久久亚洲av成人无码电影|