非唯一集合的帕斯卡定理?
当集合包含时,帕斯卡规则在计算集合的子集时效果很好独特的实体。
当集合包含重复项目时,此规则是否有修改?
例如,当我尝试查找字母 A、B、C、D 的组合数时,很容易看出它是 1 + 4 + 6 + 4 + 1(来自帕斯卡三角形)= 16,或者 15,如果我删除了“不使用任何字母”条目。
现在,如果字母集是 A、B、B、B、C、C、D 该怎么办? 手工计算,我可以确定子集之和为:1 + 4 + 8 + 11 + 11 + 8 + 4 + 1 = 48,但这不符合我所知道的三角形。
问题:如何修改帕斯卡三角形以考虑集合中的重复实体?
Pascal's rule on counting the subset's of a set works great, when the set contains unique entities.
Is there a modification to this rule for when the set contains duplicate items?
For instance, when I try to find the count of the combinations of the letters A,B,C,D, it's easy to see that it's 1 + 4 + 6 + 4 + 1 (from Pascal's Triangle) = 16, or 15 if I remove the "use none of the letters" entry.
Now, what if the set of letters is A,B,B,B,C,C,D? Computing by hand, I can determine that the sum of subsets is: 1 + 4 + 8 + 11 + 11 + 8 + 4 + 1 = 48, but this doesn't conform to the Triangle I know.
Question: How do you modify Pascal's Triangle to take into account duplicate entities in the set?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
如果没有重复项(如前面的海报所指出的那样,在一个集合中),每个元素要么在子集中,要么在子集中。 所以你有 2^n 个子集。 对于重复项,(在“多重集中”中)您必须考虑每个元素在“子多重集中”中出现的次数。 如果用m_1,m_2...m_n表示每个元素重复的次数,那么子袋的数量就是(1+m_1) * (1+m_2) * ... (1+m_n)。
Without duplicates (in a set as earlier posters have noted), each element is either in or out of the subset. So you have 2^n subsets. With duplicates, (in a "multi-set") you have to take into account the number the number of times each element is in the "sub-multi-set". If it m_1,m_2...m_n represent the number of times each element repeats, then the number of sub-bags is (1+m_1) * (1+m_2) * ... (1+m_n).
您根本不需要修改帕斯卡三角形。 研究 C(k,n) 你会发现——你基本上需要除以原始结果来考虑等效字母的排列。
例如,A B1 B2 C1 D1 == A B2 B1 C1 D1,因此您需要将 C(5,5) 除以 C(2,2)。
You don't need to modify Pascal's Triangle at all. Study C(k,n) and you'll find out -- you basically need to divide the original results to account for the permutation of equivalent letters.
E.g., A B1 B2 C1 D1 == A B2 B1 C1 D1, therefore you need to divide C(5,5) by C(2,2).
是的,如果您不想考虑集合,请考虑“因子”的概念。 多少个因数
如果 p1 是不同的素数,则有 。 如果ai全为1,那么这个数字就是2^n。 一般来说,正如 David Nehme 所说,答案是 (a1+1)(a2+1)...(an+1)。
哦,请注意,你的手写答案是错误的,它应该是 48,如果你不想计算空集,则应该是 47。
Yes, if you don't want to consider sets, consider the idea of 'factors.' How many factors does:
have if p1's are distinct primes. If the ai's are all 1, then the number is 2^n. In general, the answer is (a1+1)(a2+1)...(an+1) as David Nehme notes.
Oh, and note that your answer by hand was wrong, it should be 48, or 47 if you don't want to count the empty set.
一套仅包含独特的项目。 如果有重复,那么它就不再是一个集合。
A set only contains unique items. If there are duplicates, then it is no longer a set.
看起来您想知道有多少个子多集,例如 3 个元素。 这个数学运算很快就会变得非常棘手。 这个想法是,您希望将实现这一目标的所有方式组合加在一起。 所以你有 C(3,4) = 4 种没有重复元素的方法。 B 可以以 C(1,3) = 3 种方式重复两次。 B可以以1种方式重复3次。 C 可以以 C(1,3) = 3 种方式重复两次。 总共11个。 (你手工得到的 10 是错误的。抱歉。)
一般来说,试图做到这一点的逻辑太难了。 跟踪它的更简单方法是写出一个多项式,其系数具有您想要相乘的项。 对于帕斯卡三角形,这很容易,多项式是 (1+x)^n。 (您可以使用重复平方来更有效地计算此值。)在您的情况下,如果一个元素重复两次,您将得到一个 (1+x+x^2) 因子。 3 次就是 (1+x+x^2+x^3)。 因此,您的具体问题将按如下方式解决:
如果您想在代码中生成这些数字,我将使用多项式技巧来组织您的思维和代码。 (您将使用系数数组。)
It looks like you want to know how many sub-multi-sets have, say, 3 elements. The math for this gets very tricky, very quickly. The idea is that you want to add together all of the combinations of ways to get there. So you have C(3,4) = 4 ways of doing it with no duplicated elements. B can be repeated twice in C(1,3) = 3 ways. B can be repeated 3 times in 1 way. And C can be repeated twice in C(1,3) = 3 ways. For 11 total. (Your 10 you got by hand was wrong. Sorry.)
In general trying to do that logic is too hard. The simpler way to keep track of it is to write out a polynomial whose coefficients have the terms you want which you multiply out. For Pascal's triangle this is easy, the polynomial is (1+x)^n. (You can use repeated squaring to calculate this more efficiently.) In your case if an element is repeated twice you would have a (1+x+x^2) factor. 3 times would be (1+x+x^2+x^3). So your specific problem would be solved as follows:
If you want to produce those numbers in code, I would use the polynomial trick to organize your thinking and code. (You'd be working with arrays of coefficients.)
尽管数学集合确实包含唯一的项目,但在现实编程世界中,您可能会遇到“集合”中重复项目的问题。 请参阅 this thread 以 Lisp 联合为例。
Even though mathematical sets do contain unique items, you can run into the problem of duplicate items in 'sets' in the real world of programming. See this thread on Lisp unions for an example.