def optimal_set_cover(universe, subsets, costs):
pset = powerset(subsets.keys())<EOL>best_set = None<EOL>best_cost = float("<STR_LIT>")<EOL>for subset in pset:<EOL><INDENT>covered = set()<EOL>cost = <NUM_LIT:0><EOL>for s in subset:<EOL><INDENT>covered.update(subsets[s])<EOL>cost += costs[s]<EOL><DEDENT>if len(covered) == len(universe) and cost < best_cost:<EOL><INDENT>best_set = subset<EOL>best_cost = cost<EOL><DEDENT><DEDENT>return best_set<EOL>
Optimal algorithm - DONT USE ON BIG INPUTS - O(2^n) complexity!
    Finds the minimum cost subcollection os S that covers all elements of U

    Args:
        universe (list): Universe of elements
        subsets (dict): Subsets of U {S1:elements,S2:elements}
        costs (dict): Costs of each subset in S - {S1:cost, S2:cost...}