Combinations and Permutations
Posted: Thu Oct 27, 2005 2:42 am
I know in STL you can use the next_permutation algorithm to get permutations in linear time, but how do you get QUICK combinations in C++? e.g. how can I find all the different ways to choose 10 things out of 500 things in less than a few seconds, when the order doesn't matter?
I ask because I am having trouble doing this type of problems (e.g. Doublets and Crypt Kicker). Right now I am using a boolean array to get combinations. In the above example, I would have an array of 10 T and 490 F, and I would call next_permutation on the boolean array to get the next combination, but this seems to be too slow for most questions.
Has anyone found really clever ways to do this?
I ask because I am having trouble doing this type of problems (e.g. Doublets and Crypt Kicker). Right now I am using a boolean array to get combinations. In the above example, I would have an array of 10 T and 490 F, and I would call next_permutation on the boolean array to get the next combination, but this seems to be too slow for most questions.
Has anyone found really clever ways to do this?