鉴于套带数字的量

鉴于套带数字的量

本文介绍了鉴于套带数字的量,发现了一组不包括任何给定的数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

鉴于套的量与数字(例如0-20),我们要求找到的最大组数由0-20不包括任何给定的套(它可以包括数从一组,而不是整个集)例如:设置的最大编号为8,给出的套

Given an amount of sets with numbers (0-20 e.g) , we are asked to find the maximum set of numbers from 0-20 that doesn't include any of the given sets(it can include numbers from a set,but not the whole set)For example :Setting the max number 8 and given the sets

{1,2}
 {2,3}
 {7}
 {3,4}
 {5,6,4},

一个最大值的解决方案是集合{1,3,5,6,8}。我想重新presenting它作为一个图形,然后将其诱导到的最大的独立设置的问题,但似乎只是为了工作,如果集是由只能从对等,不stand.Any想法?谢谢前进。

one maximum solution is the set {1, 3, 5, 6, 8}.I was thinking of representing it as a graph and then inducting it to the Max Independent Set problem, but that seems to work only if the sets were consisted only from pairs,which doesn't stand.Any idea?Thanks in advance.

推荐答案

使用位图的每一组,设置相应的位。如果有小于32的成员,你可以只使用一个uint32_t的。全套包含然后可以通过屏蔽掉所有成员(即所有集合的并集)与特定的位图,然后用异或与特定的位图来计算。其结果将是全部为0,如果一个子集,否则结果将是最大独立集的成员。

Use a bit map for each set, setting the appropriate bit. If there are less than 32 members, you can just use a uint32_t. Full set inclusion can then be computed by masking out all members (i.e. the union of all the sets) with a specific bit map, and then using xor with the specific bit map. The result will be all 0's if a subset, otherwise the result will be a member for the Max Independent Set.

这篇关于鉴于套带数字的量,发现了一组不包括任何给定的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 09:58