← 返回 roblox 的题目列表Number of Ways to Wear Different Hats to Each Other
类型:online_judge
Problem: Number of Ways to Wear Different Hats to Each Other
There are n people numbered from 0 to n - 1. There are multiple hats, each represented by a positive integer. Person i is willing to wear only hats in hats[i].
Return the number of valid assignments such that:
Each person wears exactly one hat.
No two people wear the same hat.
Person i wears a hat from hats[i].
Return the answer modulo 10^9 + 7.
The interview mentioned that the constraints were smaller than the original LeetCode problem, so brute force/backtracking might be acceptable. The constraints below are for the standard version.
Input Format
n
k0 h00 h01 ...
k1 h10 h11 ...
...
kn-1 ...
For each person i, the first integer ki is the number of hats they like, followed by ki hat IDs.
Output Format
Print one integer: the number of valid assignments.
Constraints
1 <= n <= 10
1 <= hats[i].length <= 40
1 <= hats[i][j] <= 40
Each person's list has no duplicate hats.
Example
Input
3
2 3 4
2 4 5
1 5
Output
1