An efficient function for k-th combination with no repetition?
显示 更早的评论
I am looking for a function that accepts a vector V of n elements with no repetition and integers k, i, and returns the i-th combination (in lexicographic order) of k elements of V. It is essential the function do not generate all the combinations and then select the i-th.
Example: V=[1 2 3 4 5], k= 3, i=6. Expected result is: [1 4 5].
Why? Beacuse all combinations of 3 elements of V ordered lexicographically are: 123, 124, 125, 134, 135, 145, 234, 235, 245, 345. And, so the 6-th is 145.
2 个评论
Akira Agata
2018-12-21
Question for clarification.
Should the order in a vector V be kept in the output?
Because, if not, all combinations of 3 elements will be 123, 124, 125, 132, 134,.... etc.
ZoranSt
2018-12-21
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Introduction to Installation and Licensing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!