简体   繁体   English

如何找到从 k 个子集中选择一个的组合数

[英]How to find number of combinations of choosing one from k subsets

Consider we have set S:考虑我们已经设置了 S:

S = {1,2,3,4,5,6} S = {1,2,3,4,5,6}

and 3 (say k) subsets of S:和 S 的 3 个(比如 k 个)子集:

S_1 = {1,2,3} S_1 = {1,2,3}

S_2 = {2,3,4,5} S_2 = {2,3,4,5}

S_3 = {1,3,6} S_3 = {1,3,6}

What is the total number of cases choosing one element from each subsets?从每个子集中选择一个元素的案例总数是多少?

Same element cannot picked from different subset, and the order is not considered.不能从不同的子集中挑选相同的元素,并且不考虑顺序。

For example,例如,

S_1 = {2}, S_2 = {3}, S_3 = {6} S_1 = {2},S_2 = {3},S_3 = {6}

and

S_1' = {3}, S_2' = {2}, S_3' = {6} S_1' = {3},S_2' = {2},S_3' = {6}

considered as same.视为相同。 And

S_1' = {3}, S_2' = {3}, S_3' = {1} S_1' = {3},S_2' = {3},S_3' = {1}

is invalid since S_1' and S_2' choose the same element.无效,因为 S_1' 和 S_2' 选择了相同的元素。

How can I formulate this?我该如何制定这个?

This problem is similar to counting the number of perfect matchings in a bipartite graph .这个问题类似于计算二分图完美匹配的数量。

To model it this way, construct a bipartite graph where A = { 1, ..., k }, B is the original set S, and an edge from x ∈ A to y ∈ B exists when y is a member of the set S_ x .对 model 这样,构造一个二分图,其中 A = { 1, ..., k },B 是原始集合 S,当y是集合的成员时,存在从x ∈ A 到y ∈ B 的边S_x

A perfect matching corresponds with a subset of the edges matching every element of A to a distinct element of B;完美匹配对应于将 A 的每个元素与 B 的不同元素匹配的边的子集; for each set S_ x this matching selects a distinct element y ∈ S_ x .对于每个集合S_x,此匹配选择一个不同的元素yS_x That said, multiple distinct matchings may match the same k elements from B, which means this overcounts due to order not being considered in your problem (ie for your purpose, it doesn't matter which edges map from A to those k elements).也就是说,多个不同的匹配可能匹配来自 B 的相同k个元素,这意味着由于在您的问题中未考虑顺序而导致的过度计数(即,出于您的目的,从 A 到那些k元素的哪条边 map 并不重要)。 Nonetheless, the problems are quite similar and it's likely that each can be reduced to the other.尽管如此,这些问题非常相似,并且很可能每个问题都可以简化为另一个问题。

According to this answer on math.SE there is no known efficient algorithm for counting perfect matchings, so there is probably no known efficient algorithm for this similar problem, either.根据这个关于 math.SE 的答案,没有已知的计算完美匹配的有效算法,因此对于这个类似问题也可能没有已知的有效算法。 That suggests you're unlikely to do much better than a backtracking search of some sort.这表明您不太可能比某种回溯搜索做得更好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM