generate all subsets of size k from a set

后端 未结 9 1336
南旧
南旧 2020-12-08 03:30

I want to generate all the subsets of size k from a set.

eg:-say I have a set of 6 elements, I have to list all the subsets in which the cardinality of elements is 3

9条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-08 04:15

    Find a working code below

    #include
    #include
    #include
    
    using namespace std;
    
    void print( list l){
        for(list::iterator it=l.begin(); it!=l.end() ; ++it)
                cout << " " << *it;
        cout< &l){
        if(left==0){
            print(l);
            return;
        }
        for(int i=index; i lt;   
        subset(array,5,3,0,lt);
    
    
        return 0;
    }
    

提交回复
热议问题