• <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

            久久夜色tv网站| 久久久久久久精品妇女99 | 精品无码久久久久久久动漫| 久久精品二区| 久久久久久久人妻无码中文字幕爆| 九九精品99久久久香蕉| 久久精品三级视频| 国产亚洲色婷婷久久99精品| 久久精品国产99久久香蕉| 久久亚洲精品成人av无码网站| 久久se精品一区二区影院| 久久婷婷五月综合色奶水99啪 | 久久人人爽人人爽人人片AV高清| 久久国产精品成人免费| 精品久久久久久国产| 狠狠精品干练久久久无码中文字幕 | 久久久久高潮综合影院| 国产精品99久久精品爆乳| 无遮挡粉嫩小泬久久久久久久| 久久久久久A亚洲欧洲AV冫| 久久91综合国产91久久精品| 亚洲狠狠婷婷综合久久久久| 久久综合色老色| 亚洲欧美另类日本久久国产真实乱对白 | 亚洲国产成人久久笫一页| 国产成人精品久久综合 | 九九99精品久久久久久| 久久久久亚洲av无码专区导航| 久久人人爽人人爽人人爽| 思思久久好好热精品国产| 久久人人青草97香蕉| 亚洲国产成人精品女人久久久 | 国产精品免费久久久久久久久| 91精品国产91久久综合| 国产精品久久久久久久久免费| 蜜臀av性久久久久蜜臀aⅴ麻豆| 狠狠色婷婷久久综合频道日韩| 久久笫一福利免费导航 | 国产香蕉久久精品综合网| 久久91精品国产91| 熟妇人妻久久中文字幕|