Участник:Turk0v/Smallest Sufficient Team

Материал из DISCOPAL
Перейти к: навигация, поиск
class Solution:
    def smallestSufficientTeam(self, req_skills: List[str], people: List[List[str]]) -> List[int]:
        d = {e:i for i, e in enumerate(req_skills)}
        res_list = [[0] * len(people) for _ in range(1 << len(req_skills))]
        res_list[0] = list()
        for i, sk in enumerate(people):
            tmp_val = 0
            for e in sk:
                tmp_val |= (1 << d[e])
            for k, v in enumerate(res_list):
                res_req = k | tmp_val
                if res_req != k and len(res_list[res_req]) > len(v) + 1:
                    res_list[res_req] = v + [i]
        return res_list[-1]