Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def set_cover(universe_, sets_):
- chosen_sets = []
- while universe_:
- best_set = max(sets_, key=lambda s: len(universe_.intersection(s)))
- chosen_sets.append(best_set)
- universe_ -= best_set
- return chosen_sets
- universe = {int(x) for x in input().split(', ')} # int
- n = int(input())
- sets = [set(map(int, input().split(', '))) for _ in range(n)] # int
- result = set_cover(universe, sets)
- for i in range(len(result)):
- result[i] = sorted(result[i])
- print(f'Sets to take ({len(result)}):')
- [print("{ " + f"{', '.join(map(str, s))}" + " }") for s in result]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement