combinations ( NchooseK)



 DEVELOP > c-Plus-Plus > combinations ( NchooseK)

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "Gary Wessle"
Date: 22 Aug 2006 09:54:18 PM
Object: combinations ( NchooseK)
Hi
is there a function or lib in c++ which may already do this.
given {a,b,c}, give all the combinations which contain 2 letters,
would be {a,b}, {a,c}, {b,c}
thanks
.

User: "Mark P"

Title: Re: combinations ( NchooseK) 23 Aug 2006 12:20:54 PM
Gary Wessle wrote:

Hi

is there a function or lib in c++ which may already do this.

given {a,b,c}, give all the combinations which contain 2 letters,

would be {a,b}, {a,c}, {b,c}

thanks

Not in the standard library. Though you could make use of
std::next_permutation to achieve your result. If you want n choose k,
make a mask of length n with (n-k) 0s and k 1s: {0 0 0... 1 1 1}.
Repeatedly apply next_permutation to this mask and, for each such mask,
apply it to your array of values, keeping those values that match a 1 in
the mask.
.


  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER