查找数组的第i个组合 [英] Find i-th combination of an array

查看:118
本文介绍了查找数组的第i个组合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


问题是在第一个组合中给了我一个数组,我必须找到该数组的第i个组合. (0< i<总组合)

组合的总数可能很大,我不想找到第2到第(i-1)个组合.
我只想立即知道第i个组合.

请给我一些进展.

谢谢

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

推荐答案

我猜你在找 bool next_permutation [^ ]

称它为i次,您将获得第i个排列. (或i-1组合)

最好的问候
Espen Harlinn
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


首先,我要弄清楚是否有某种方法可以对数组进行排序,以便可以确定组合是否在选定组合的上方或下方,您可以基本上检查一下是否匹配在中心点上方或下方,然后在数组顶部或底部的中心上方或下方.这称为二进制搜索: http://en.wikipedia.org/wiki/Binary_search [
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[^]


这篇关于查找数组的第i个组合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆