A cheese fair picks a tasting panel of exactly k people. The candidates come in groups (farmers, chefs, shop owners, ...): groups[g] is how many candidates are in group g, and every candidate is a different person. The rules say the panel must include at least one person from every group.
Write panel_count(groups: list[int], k: int) -> int returning the number of different panels (sets of k people) that satisfy the rule. Return the exact integer; no modulus.
panel_count([2, 1], 2) # 2 (the lone chef plus either farmer)
panel_count([2, 2], 2) # 4 (C(4,2) = 6, minus the 2 panels from one group only)
panel_count([3, 1, 1], 2) # 0 (3 groups can't all fit on a panel of 2)
panel_count([4, 5, 6], 3) # 120 (one from each: 4 · 5 · 6)
Counting the good panels head-on is awkward, so count the bad ones and use inclusion-exclusion: start from all C(total, k) panels, subtract those that miss group 1, those that miss group 2, ..., add back those that miss two given groups (subtracted twice), and so on. A panel that misses a set S of groups is just a k-subset of the people outside S.
Constraints: 1 <= len(groups) <= 10, 1 <= groups[g] <= 500, 0 <= k <= sum(groups). math.comb is fine to use.
Show hint
Loop over every subset S of groups as a bitmask 0 .. 2^len - 1: add (-1) ** |S| * comb(total - sum of sizes in S, k).