C# 有放回(重复)组合算法
2013-06-02 22:04
295 查看
static List<string> GetAllZuhe(List<string> list, int n) { if (n <= 1) { return list; } else { List<string> rl = new List<string>(); foreach (string x in list) { foreach (string y in GetAllZuhe(list, n - 1)) { rl.Add(x + y); } } return rl; } } }
static void Main(string[] args) { List<string> list = new List<string>(); list.Add("1"); list.Add("2"); list.Add("3"); list.Add("4"); List<string> allList=GetAllZuhe(list,3 ); Console.WriteLine(allList.Count+ "\n"); bool flag = true; foreach (string s in allList) { if (flag) Console.Write(s+" "); else Console.Write(s + "\n"); flag = !flag; } Console.ReadLine(); }
相关文章推荐
- [ASP.NET(C#)] - 解决了防止用户重复登陆和session超时
- c# 关于LISTBOX的添加项的问题 以及不重复插入
- C# ASP.NET B/S模式下,采用lock语法 实现多用户并发产生不重复递增单号的一种解决方法技术参考
- [C#]将1~100随机不重复的放入数组
- C#产生随机数 不重复
- C#1-100不重复的随机数
- C#产生无重复随机数
- C#怎样避免产生的随机数是重复的呢?
- C#的解题思路(1):不重复随机数的产生问题 .
- C# 禁止windows程序重复运行的两种基本方法
- <C#>找出数组中重复次数最多的数值
- C#禁止重复提交
- [转载]C# Random 生成不重复随机数
- C#的解题思路(1):不重复随机数的产生问题
- 关于产生不重复随机数的算法 C#
- 使用c#生成不重复的随机数
- C#删除数组中的重复项
- C#生成不重复的随机数(转)
- C#中怎样随机输出从0到100的数字且不重复(不用数组)
- c#扩展SPRING,配置里有不存在的业务系统xml导致不能启动问题,把配置文件里有重复的服务ID找出来并写入到日志