Subset and Set Cover

橙三吉。 提交于 2019-12-01 13:18:13

问题


We are given a number of locks and to open these locks we need exactly that set of people to open that lock. Given the number of people we have and the number of locks that needs to opened, we need a specification on how to distribute the keys amongst the available people such that any number of required people to open that lock can open it, but no group less that number of required people can open it.

The number of people will be in range of 1-9 and number of people required to open the lock will be in range of 0-9

Consider the following examples

Number of people available = 2

Number of required = 1 Ans :{{0},{0}}

Any one of them can open it, so they are both given the same keys.

Number of people available = 5

Number of required = 3

Ans: {{0, 1, 2, 3, 4, 5},{0, 1, 2, 6, 7, 8},{0, 3, 4, 6, 7, 9},{1, 3, 5, 6, 8, 9},{2, 4, 5, 7, 8, 9}}

Can someone please help me with how to go about this question.

Thank You


回答1:


Let n be the total number of people, and let m be the desired minimum number of people to open all the locks.

Then, there are two requirements:

  • For each lock, any set of m people must contain at least one person with the key to that lock. In other words, the set of people without a given key must contain fewer than m people. So each key must be distributed to at least n − m + 1 people.
  • For each set of m − 1 people, there must be at least one lock that none of them has the key to. In other words, if you turn this around at look at the "everyone else" set, which has n − m + 1 people, you can say that for every set of n − m + 1 people, there must be at least one key that is only held by that set.

Putting these two requirements together, we actually have a one-to-one mapping between (keys) and (sets of n − m + 1 people).

So you just need to find all sets of n − m + 1 people (which is trivial to do in O(2n) time, and not too hard to do in O(C(nn − m + 1)) time). For each set, create a key and distribute it to the people in that set.



来源:https://stackoverflow.com/questions/41475811/subset-and-set-cover

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!