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