Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi,
The problem is that I am given an array in the first combination and I have to find i-th combination of this array. (0 < i < total combinations)

Total number of combinations could be large and I don't want to find the combinations from 2nd to (i-1)-th.
I just want to know the i-th combination immediately.

Please give me some advance.

Thanks
Posted

I guess you are looking for bool next_permutation[^]

Call it i times and you'll have the i-th permutation. (or the i-1 combination)

Best regards
Espen Harlinn
 
Share this answer
 
Comments
Sandeep Mewara 25-May-12 0:56am    
My 5!
Espen Harlinn 25-May-12 3:29am    
Thank you, Sandeep :-D
Duc Huy Nguyen 25-May-12 15:17pm    
The problem í that I don't want to call the method for i times :)
First I would figure out if there is someway to sort the array so that it can be determined if the combination required if above or below the a selected combination they you can basically check if the match is above or below the center point, then above or below the center of either the top or the bottom of the array. This is called a binary search: http://en.wikipedia.org/wiki/Binary_search[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900