← 返回 uber 的题目列表Number of Ways to Wear Different Hats to Each Other
类型:qbank
Given n people and 40 hat types where each person lists the hats they are willing to wear, count the assignments in which every person gets exactly one liked hat and no two people share a hat, modulo 10^9 + 7.
Number of Ways to Wear Different Hats to Each Other
Given n people and 40 hat types where each person lists the hats they are willing to wear, count the assignments in which every person gets exactly one liked hat and no two people share a hat, modulo 10^9 + 7.
SWE
dp
state-compression-dp
bitmask
hard
Frequency
Single report
Last asked
2026-04-01
Stage
phone-screen
Number of Ways to Wear Different Hats to Each Other
There are n people and 40 possible hat types. hats[i] lists the hats person i is willing to wear.
Return the number of valid assignments where every person gets exactly one hat they like and no two people wear the same hat, modulo 10^9 + 7.
Examples
Example 1:
Input: hats = [[3,4],[4,5],[5]]
Output: 1
Example 2:
Input: hats = [[3,5,1],[3,5]]
Output: 4
Constraints
1 <= hats.length <= 10
1 <= hats[i].length <= 40
1 <= hats[i][j] <= 40
Each hats[i] contains distinct values.