I have forgotten

• https://me.yahoo.com
COST (GBP)
0.90
0.00
0

# unrank combination

viewed 2974 times and licensed 71 times
Generates the combination of \e n objects out of \e m, of the given rank
Controller: CodeCogs

C++

## Unrank Combination

 std::vectorunrank_combination( int m int n int rank )
This function generates the combination of n objects out of m, of the given order. The combinations are considered to be ordered lexicographically, as in the following diagram

$\begin{array}{rcccccc}&space;1:&space;&&space;1,&space;&&space;2,&space;&&space;\ldots&space;&&space;n&space;-&space;1,&space;&&space;n&space;\\&space;2:&space;&&space;1,&space;&&space;2,&space;&&space;\ldots&space;&&space;n&space;-&space;1,&space;&&space;n&space;+&space;1&space;\\&space;3:&space;&&space;1,&space;&&space;2,&space;&&space;\ldots&space;&&space;n&space;-&space;1,&space;&&space;n&space;+&space;2&space;\\&space;\ldots&space;\\&space;m&space;-&space;n&space;+&space;1:&space;&&space;1,&space;&&space;2,&space;&&space;\ldots&space;&&space;n&space;-&space;1,&space;&&space;m&space;\\&space;m&space;-&space;n&space;+&space;2:&space;&&space;1,&space;&&space;2,&space;&&space;\ldots&space;&&space;n,&space;&&space;n&space;+&space;1&space;\\&space;m&space;-&space;n&space;+&space;3:&space;&&space;1,&space;&&space;2,&space;&&space;\ldots&space;&&space;n,&space;&&space;n&space;+&space;2&space;\\&space;\ldots&space;\\&space;last&space;-&space;2:&space;&&space;m&space;-&space;n,&space;&&space;m&space;-&space;n&space;+&space;1,&space;&&space;\ldots&space;&&space;m&space;-&space;1,&space;&&space;m&space;\\&space;last&space;-&space;1:&space;&&space;m&space;-&space;n,&space;&&space;m&space;-&space;n&space;+&space;2,&space;&&space;\ldots&space;&&space;m&space;-&space;1,&space;&&space;m&space;\\&space;last:&space;&&space;m&space;-&space;n&space;+&space;1,&space;&&space;m&space;-&space;n&space;+&space;2,&space;&&space;\ldots&space;&&space;m&space;-&space;1,&space;&&space;m&space;\end{array}$

where the rank of the last combination is

$\mathrm{last}&space;=&space;\left(&space;\begin{array}{c}&space;m&space;\cr&space;n&space;\end{array}&space;\right)&space;=&space;\frac{m!}{n!(m&space;-&space;n)!}$

## References:

SUBSET, a C++ library of combinatorial routines, http://www.csit.fsu.edu/~burkardt/cpp_src/subset/subset.html

### Example 1

#include <codecogs/maths/combinatorics/combinations/unrank_combination.h>
#include <iostream>
int main()
{
std::vector<int> comb = Maths::Combinatorics::Combinations::unrank_combination(6, 3, 10);
std::cout << "Size of the combination: " << comb.size() << std::endl;
for (int i = 0; i < comb.size(); i++)
std::cout << comb[i] << "  ";
std::cout << std::endl;
return 0;
}
Output:
Size of the combination: 3
1  5  6

### Returns

the combination with the given index

### Authors

Lucian Bentea (August 2005)
##### Source Code

Source code is available when you agree to a GP Licence or buy a Commercial Licence.

Not a member, then Register with CodeCogs. Already a Member, then Login.