I don't know how to write the title for this question. The existing title may not be precise.
Here is the problem:
I have m groups (arrays), say, 4 groups. Each group contains some numbers. What we wish is that each group gives one number out, and totally the resulting 4 numbers (each from one group) are distinct.
Now given these 4 groups, how can I make sure they fit to our wish?
For example,
A: 0, 2, 3
B: 0, 2
C: 2, 3
D: 1
The above 4 groups can fit to our wish. D gives 1, C gives 3, B gives 2, A give 0.
But if
A: 2
B: 2
C: 2, 3
D: 1
are bad. We can't let each group give an distinct number.
My idea is the most stupid way that I just do backtrack on all elements from all groups to get every combination of elements and see those elements from one combination are distinct or not.
Anyone has better idea?