从一组x项的随机抽取n项所有可能的组合(算法)

编程入门 行业动态 更新时间:2024-10-13 06:14:50
本文介绍了从一组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:

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

6选4 = 15

更多推荐

从一组x项的随机抽取n项所有可能的组合(算法)

本文发布于:2023-11-29 14:13:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1646620.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:组合   算法

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!