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

            久久高清一级毛片| 亚洲级αV无码毛片久久精品| 久久亚洲中文字幕精品有坂深雪| 老色鬼久久亚洲AV综合| 日韩亚洲欧美久久久www综合网| 久久精品成人免费国产片小草 | aaa级精品久久久国产片| 久久91精品国产91久久户| 久久久久综合国产欧美一区二区| 99久久精品免费看国产一区二区三区| 狠狠色丁香久久婷婷综合| 亚洲国产成人久久综合碰碰动漫3d | 国产欧美久久一区二区| 午夜精品久久久久久| 国产精品久久久久久搜索| 国产精品乱码久久久久久软件 | 久久精品国产99久久香蕉| 亚洲色欲久久久综合网东京热| 狠狠综合久久综合中文88| 五月丁香综合激情六月久久| 人妻精品久久久久中文字幕| 99久久精品费精品国产一区二区| 亚洲色欲久久久久综合网| 国产免费久久久久久无码| 99久久99久久精品免费看蜜桃| 亚洲精品午夜国产va久久| 久久久久一本毛久久久| 久久天堂电影网| 色综合久久中文综合网| 国产麻豆精品久久一二三| 久久精品亚洲一区二区三区浴池 | 久久天天日天天操综合伊人av| 久久se精品一区精品二区| 久久夜色精品国产噜噜麻豆 | 久久国产亚洲精品| 一级做a爰片久久毛片免费陪| 欧美久久综合性欧美| 欧美亚洲另类久久综合| 久久综合中文字幕| 九九久久精品国产| 一本久久免费视频|