本文介绍了关于集合中所有分区的程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要一个有关set中所有分区的程序 例如: 设置:{1,2,3} 所有分区: 1.{{1},{2},{3}} 2.{{1,2},{3}} 3.{{1},{2,3}} 4.{{1,3},{2}}
I need a program about all of partitions from set example: set:{1,2,3} all of partitions: 1.{{1},{2},{3}} 2.{{1,2},{3}} 3.{{1},{2,3}} 4.{{1,3},{2}}
推荐答案NN:"{{2},{2,3}}和{{ 1,3},{2}}" 我认为您在编写"{{2},{2,3}}时在这里输入了错误.但是,至少,您正朝着准确说明您的要求迈出第一步.您刚刚指定了每个排列包括两个elements是一个"true"集:这意味着{1,3}和{3,1}是等效的……例如,我认为(但不是完全确定)此要求会排除使用" Linq中的不同运算符. CodeProject是您的朋友:Adrian Akison撰写的使用C#泛型的排列,组合和变体" [ ^ ]! 以及埃里克·利珀特(Eric Lippert)的这篇博客文章,使用LINQ计算笛卡尔积" [ ^ ],可能会有所帮助. 接下来:向我们展示一些代码,无论您是Linq还是选择其他类型的合成:) NN: "not diffrenet between {{2},{2,3}} and {{1,3},{2}}" I think you made a typing error here when you wrote "{{2},{2,3}}. But, at least you are making a first step towards precisely stating your requirements. You have just specified that each permutation that includes two elements is a ''true'' set: which means {1,3} and {3,1} are equivalent ... this requirement, for example, I believe (but am not totally sure) would rule out using the ''Distinct operator in Linq. CodeProject is your friend: "Permutations, Combinations, and Variations using C# Generics" by Adrian Akison"[^] ! And this blog post by Eric Lippert, "Computing a Cartesian Product with LINQ"[^], may be helpful. Next: show us some code, whether you Linq, or opt for other types of composition :)
更多推荐
关于集合中所有分区的程序
发布评论