从一组x项的随机抽取n项所有可能的组合(算法) [英] All possible combinations of n items selected randomly from a set of x items (algorithm)

查看:209
本文介绍了从一组x项的随机抽取n项所有可能的组合(算法)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个集合X线项目,例如中(A,B,C,D,E,F) 我需要知道,计算n项和什么有多少组合公式生成所有可能的组合算法 例如 如果我们需要选择4个项目从列表中随机。 这4个项目可能是: (A,B,C,D)或 (A,B,C,E)或 (A,B,C,F)或 (A,B,D,E)...等 我需要,其计算多少项集将不重复生成式中,也就是我们认为(A,B,C,D),为所得的组合之一,我们可以不考虑相同的项与更换的物件的位置集合中的像另一个所得组合(A,B,D,C) 此外,我需要生成所有可能的组合在任何编程语言的算法。 [C#,VB.NET,JAVA,C ++]

I have a set of x string items e.g("A","B","C","D","E","F") I need to know the formula that calculates how many combinations of n items and what is the algorithm that generates all possible combinations e.g if we need to select 4 items from the list randomly. those 4 items could be: ("A","B","C","D") or ("A","B","C","E") or ("A","B","C","F") or ("A","B","D","E") ...etc I need the formula that calculates how many sets of items will be generated without repetition, that is we consider ("A","B","C","D") as one of the resulted combinations we cannot consider the same items as another resultant combination with replacing the positions of the items in the set like ("A","B","D","C") Also I need the algorithm that generates all possible combinations in any programming language. [C#,VB.NET,Java,C++]

感谢您的任何帮助。

推荐答案

选择P输出的n个项目,这是公式来告诉你有多少组合也有。

Choosing p out of n items, this is the formula to tell you how many combinations there are.

                  n!
n choose p  = -----------
               p! (n-p)!

谷歌计算器会做数学题给你:

Google calculator will do the math for you:

http://www.google.com/search?q=6+选择+ 4

6选4 = 15

这篇关于从一组x项的随机抽取n项所有可能的组合(算法)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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