c++ - which is the best way to generate choices out of a given set of numbers? -
For example, if it is given to make all the options between 1 to 5 and the answer comes in this way ..
1,2,3,4,5, 1-2,1-3,1-4,1-5,2-3,2-4,2-5, 3-4,3 -5,4-5, 1-2-3,1-2-4,1-2-5,1-3-4, ....., 1-2-3-4- 5
Can someone recommend fast algorithms?
Just generate all 2 ^ N - 1 for one (or Zero if you want to include the empty set), the integers are indicated by the set bits in your set number. For example if you have 5 elements {A, B, C, D, E}, then the number 6 = 00110 will represent the subset {C, D}.
Comments
Post a Comment