查找可以补全为无重复元组的子集

发布于 2024-08-31 17:21:46 字数 1073 浏览 3 评论 0原文

我们有一组 A_1,...,A_n 的集合。目标是为每个旧集合找到新集合。

newA_i = {a_i in A_i such that there exist (a_1,..,a_n) in (A1,..,An) with no a_k = a_j for all k and j}

因此,用语言来说,这表示我们从 A_i 中删除所有不能用于从集合 (A_1,..,A_n) 中形成元组 (a_1,..a_n) 的元素,使得该元组不包含重复项。

我的问题是如何快速计算这些新集合。如果您只是通过生成所有可能的 v 来实现此定义,这将需要指数时间。你知道更好的算法吗?

编辑:这是一个例子。现在

A_1 = {1,2,3,4}
A_2 = {2}. 

,新集合如下所示:

newA_1 = {1,3,4}
newA_2 = {2}

2 已从 A_1 中删除,因为如果您选择它,则元组将始终为 (2,2),这是无效的,因为它包含重复项。另一方面,1,3,4 是有效的,因为 (1,2)、(3,2) 和 (4,2) 是有效的元组。

另一个例子:

A_1 = {1,2,3}
A_2 = {1,4,5}
A_3 = {2,4,5}
A_4 = {1,2,3}
A_5 = {1,2,3}

现在新的集合是:

newA_1 = {1,2,3}
newA_2 = {4,5}
newA_3 = {4,5}
newA_4 = {1,2,3}
newA_5 = {1,2,3}

1 和 2 从集合 2 和 3 中删除,因为如果您从这些集合中选择 1 或 2,您将只剩下 2 个值用于集合 1、4 和 5,所以您将元组中始终存在类似于 (_,1,_,_,_)(_,_,2,_,_) 的重复项。

这个问题看起来很难,但是如果有一个多项式时间的算法就太好了。

另一种看待此问题的方法是,将集合 A_i 绘制在左侧,将值绘制在右侧,如果该值在集合中,则用一条线连接集合和值。

We have a collection of sets A_1,..,A_n. The goal is to find new sets for each of the old sets.

newA_i = {a_i in A_i such that there exist (a_1,..,a_n) in (A1,..,An) with no a_k = a_j for all k and j}

So in words this says that we remove all the elements from A_i that can't be used to form a tuple (a_1,..a_n) from the sets (A_1,..,A_n) such that the tuple doesn't contain duplicates.

My question is how to compute these new sets quickly. If you just implement this definition by generating all possible v's this will take exponential time. Do you know a better algorithm?

Edit: here's an example. Take

A_1 = {1,2,3,4}
A_2 = {2}. 

Now the new sets look like this:

newA_1 = {1,3,4}
newA_2 = {2}

The 2 has been removed from A_1 because if you choose it the tuple will always be (2,2) which is invalid because it contains duplicates. On the other hand 1,3,4 are valid because (1,2), (3,2) and (4,2) are valid tuples.

Another example:

A_1 = {1,2,3}
A_2 = {1,4,5}
A_3 = {2,4,5}
A_4 = {1,2,3}
A_5 = {1,2,3}

Now the new sets are:

newA_1 = {1,2,3}
newA_2 = {4,5}
newA_3 = {4,5}
newA_4 = {1,2,3}
newA_5 = {1,2,3}

The 1 and 2 are removed from sets 2 and 3 because if you choose the 1 or 2 from these sets you'll only have 2 values left for sets 1, 4 and 5, so you will always have duplicates in tuples that look like (_,1,_,_,_) or like (_,_,2,_,_).

This problem seems difficult, but it would be great if there was a polynomial time algorithm.

Another way to look at this is to picture the sets A_i on the left and the values on the right, with a line connecting a set and a value if the value is in the set.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦亿 2024-09-07 17:21:46

我认为分配算法在这里可能会有所帮助。基本步骤是固定 Ai 中的一个数字,然后看看该数字是否可以与从 Aj 中选择的其他数字一起使用,从每组中选择一个数字而不重复。将数字视为人,将集合 Aj 中的数字视为可能用于执行任务 j 的人。那么从每个Aj中找到不同的代表的问题就是为每个任务分配不同的人的问题。

维基百科将分配问题视为所有可能的分配以及每个分配的成本 http://en.wikipedia.org /wiki/Assignment_problem。在我们的例子中,我们可以使用 0 和 1 作为成本来表示可以做和不能做,并查看是否存在零成本答案。

I think the assignment algorithm might help here. The basic step would be to fix on a number in one of the Ai and then see if that number can be used with others chosen from the Aj to select a number from each set without repeat. Think of the numbers as people, and the numbers in set Aj as the people who might be used to perform task j. Then the problem of finding a different representative from each Aj is the problem of assigning a different person to each task.

Wikipedia treats the assignment problem as having all assignments possible and a cost for each http://en.wikipedia.org/wiki/Assignment_problem. In our case we can use 0 and 1 as costs to mean can do and can't do and look to see if there is a zero cost answer.

埋葬我深情 2024-09-07 17:21:46

我仍在考虑如何解决这个问题,但我决定尝试重写这个问题,看看它是否给我任何启发。

给定一组 N 组:

A_i = {a_i0, a_i1, ..., a_ij, ...}

找到

B_i such that x is in B_i if and only if:
   x is in A_i and
   there exists {c_0, c_1, c_2, c_3, ..., c_N} such that
      c_i = x and
      c_k is in A_k for all k and
      c_k != c_l for all k != l

I'm still thinking about how to solve this, but I decided to try rewriting the question to see if it gave me any inspiration.

Given a set of N sets:

A_i = {a_i0, a_i1, ..., a_ij, ...}

find

B_i such that x is in B_i if and only if:
   x is in A_i and
   there exists {c_0, c_1, c_2, c_3, ..., c_N} such that
      c_i = x and
      c_k is in A_k for all k and
      c_k != c_l for all k != l
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文