Subset and Set Cover

前端 未结 1 951
星月不相逢
星月不相逢 2021-01-17 01:03

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

1条回答
  •  生来不讨喜
    2021-01-17 02:02

    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.

    0 讨论(0)
提交回复
热议问题