Subset and Set Cover

一个人想着一个人 提交于 2019-12-01 14:16:48
ruakh

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.

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