avatar
s*s
1
最近遇到个问题,忘了有没有相关算法了。
有一些set, from A1 to An, each set contains a number of elements
Ai and Aj has intersection. 比如 Ai=(1,2,3,4) Aj=(3,4,7,8,9,10).
How to find the minimum number of sets from A1 to An so that
Union of these sets = Union of A1 ... An
Thanks.
avatar
sc
2
我不知道是不是有现成的算法,
不过想了一个,不知道好使不好使,
有数组B(1..M),
初始话:
建个可以反查的质数表P(i)
loop i
loop A_i(j)
k=A_i(j)
如果B(k)没值,B(k)=P(i)
否则B(k)=B(k)*P(i)
end loop
end loop
然后扫描数组B,是质数,说明stand alone,这个质数对应的set要得,
然后用这个质数除B里的每一个可以整除的元素。
一直搞一直搞,搞到它剩下一堆1和一堆合数,
然后找最小公约数什么的。
整个过程有点烦,不知道有没有简单的。

【在 s********s 的大作中提到】
: 最近遇到个问题,忘了有没有相关算法了。
: 有一些set, from A1 to An, each set contains a number of elements
: Ai and Aj has intersection. 比如 Ai=(1,2,3,4) Aj=(3,4,7,8,9,10).
: How to find the minimum number of sets from A1 to An so that
: Union of these sets = Union of A1 ... An
: Thanks.

avatar
l*g
3
http://en.wikipedia.org/wiki/Set_cover_problem
this is called "set covering problem", and is NP-complete

【在 s********s 的大作中提到】
: 最近遇到个问题,忘了有没有相关算法了。
: 有一些set, from A1 to An, each set contains a number of elements
: Ai and Aj has intersection. 比如 Ai=(1,2,3,4) Aj=(3,4,7,8,9,10).
: How to find the minimum number of sets from A1 to An so that
: Union of these sets = Union of A1 ... An
: Thanks.

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。