zoukankan      html  css  js  c++  java
  • 索引组合算法原型

    // next_permutation example
    #include <iostream>     // std::cout
    #include <algorithm>    // std::next_permutation, std::sort
    
    int make_combination(int myints[], int start , int end, int requirement_number){
        //std::cout<<"start:"<<start<<"end:"<<end<<"requirement_number:"<<requirement_number<<std::endl;
        if (start == end){
            std::cout << myints[start] << ",";
            requirement_number--;
            if (requirement_number >= 1){
                std::cout << "not ok" << std::endl;
                return 1;
            }else {
                std::cout << std::endl;
                return 0;
            }
        }
        if (1 ==requirement_number){
            requirement_number--;
            std::cout << myints[start] << std::endl;
            return 0;
        }
        std::cout<<myints[start];
        requirement_number--;
        return make_combination(myints, start+1, end, requirement_number );
    }
    
    int main () {
      int myints[] = {1,2,3};
    
      std::sort (myints,myints+3);
      int i =0;
      for(; i<3; i++){
        make_combination(myints, i, 2, 1);
      }
    
    //  std::cout << "The 3! possible permutations with 3 elements:
    ";
    //  do {
    //    std::cout << myints[0] << ' ' << myints[1] << ' ' << myints[2] << '
    ';
    //  } while ( std::prev_permutation(myints,myints+3) );
    //
    //  std::cout << "After loop: " << myints[0] << ' ' << myints[1] << ' ' << myints[2] << '
    ';
    
      return 0;
    }

     有bug,比如 1,2,3

    只能给出

    1,2

    2,3

    但是看不到

    1,3

    MySQL限时解答,24小时内友哥专业解答
    http://www.yougemysqldba.com
    如有进一步需要请联系微信onesoft007
    微博账号@友哥一指
  • 相关阅读:
    jQuery Easing 动画效果扩展
    【百度地图】标注点的动画效果
    CSS3制作404立体字体
    最长上升子序列的回溯 ZOJ 2432
    HDU 1423 最长上升公共子序列(LCIS)
    HDU 1114 完全背包问题的转化
    HDU 1085 多重背包转化为0-1背包问题
    opengl 对投影变化函数的理解
    HDU 1081 DP找最大和的矩阵
    HDU 1274 递归拼接字符串
  • 原文地址:https://www.cnblogs.com/youge-OneSQL/p/9483578.html
Copyright © 2011-2022 走看看