I am trying to solve this problem: https://www.codechef.com/problems/TSHIRTS
Little Elephant and his friends are going to a party. Each person has his own collection of T-Shirts. There are 100 different kind of T-Shirts. Each T-Shirt has a unique id between 1 and 100. No person has two T-Shirts of the same ID.
They want to know how many arrangements are there in which no two persons wear same T-Shirt. One arrangement is considered different from another arrangement if there is at least one person wearing a different kind of T-Shirt in another arrangement.
Input First line of the input contains a single integer T denoting number of test cases. Then T test cases follow.
For each test case, first line contains an integer N, denoting the total number of persons. Each of the next N lines contains at least 1 and at most 100 space separated distinct integers, denoting the ID's of the T-Shirts ith person has.
If there are no duplicates, then we can multiply out the number of t-shirts every person has.
I'm struggling to arrive at a solution for when there are duplicates.
A quick peek at the problem tag indicates that a dynamic programming solution is also possible.
I'd love some pointers on how to approach this problem.
Thanks!