# Given a valid combination, how to get its index in the sequence of integer partition

This question is extended from this Algorithm to generate integer sets fulfills restrictions, in the answer I learned the formal term of this problem, and the recursive algorithm described in that answer also gives me the desired sequence - as much large numbers located in the front as possible, for example, we will get the following output for $F(7,3,4)$:

• 4>2>1
• 3>3>1
• 3>2>2

So here is the question, given a valid combination, is it possible to get its index in the result set without generating the whole result set and searching for it?

• Yes, using the recursive formula. This is similar to mapping a $k$-subset of $\{1,\ldots,n\}$ into a number in the range $0,\ldots,\binom{n}{k}-1$, which has been described a few times on this site. – Yuval Filmus May 15 '17 at 19:48
• Hi Yuval, thanks for your comment, can you please give me the link to one of those questions? – Li Wang May 15 '17 at 19:53
• – Yuval Filmus May 15 '17 at 20:00
• Hi Yuval, can you please elaborate because I still have trouble in figuring it out. – Li Wang May 17 '17 at 13:40
• As the link shows, ranking and unranking (finding the index given the set and vice versa) essentially reduce to calculating how many solutions there are with given prefix. So, how many solutions there are in total, how many begin with $a$, how many begin with $a>b$, and so on. If you know how to calculate these (switching prefix with suffix it that problem is easier), then you can rank and unrank. See if you understand how this works for $k$-subsets of $\{1,\ldots,n\}$, which you can think of as 0/1 vectors of length $n$ containing exactly $k$ ones. – Yuval Filmus May 17 '17 at 15:36