Today is Max's birthday. He has ordered a rectangular fruit cake which is divided into N x M pieces. Each piece of the cake contains a different fruit numbered from 1 to N*M. He has invited K friends, each of whom have brought a list of their favorite fruit choices. A friend goes home happy if the piece he receives is of his favorite fruit. Note that each friend can receive only one piece of cake. Design a way for Max to find the maximum number of friends he can make happy. Input The first line of the input consists of an integer - numOfFriends, representing the number of friends(k). The next Klines consist of X+1 space-separated integers, where the first integer represents the count of choices of the th friend followed by X space-separated integers representing the fruits he likes. The next line of the input consists of an integer - numN, representing the number of rows. The next line of the input consists of an integer - numM, representing the number of columns. Output Print an integer representing the maximum number of friends he can make happy. Input The first line of the input consists of an integer - numOfFriends, representing the number of friends(k). The next Klines consist of X+1 space-separated integers, where the first integer represents the count of choices of the th friend followed by X space-separated integers representing the fruits he likes. The next line of the input consists of an integer - numN, representing the number of rows. The next line of the input consists of an integer - numM, representing the number of columns. Output Print an integer representing the maximum number of friends he can make happy. Constraints 1 ≤ numN, numM ≤ 50 0 ≤ numOfFriends ≤ 3000 0 ≤ X≤ numN*numM 1 ≤ i ≤ numOfFriends Example Input: 3 3123 12 11 2 Output 3 Explanation: In this example, a maximum of 3 friends can be made happy: Friend 1 gets fruit 3. Friend 2 gets fruit 2. Friend 3 gets fruit 1
Today is Max's birthday. He has ordered a rectangular fruit cake which is divided into N x M pieces.
Each piece of the cake contains a different fruit numbered from 1 to
N*M. He has invited K friends, each of whom have brought a list of their favorite fruit choices. A friend goes home happy if the piece he receives is of his favorite fruit. Note that each friend can receive only one piece of cake.
Design a way for Max to find the maximum number of friends he can make happy.
Input
The first line of the input consists of an integer - numOfFriends, representing the number of friends(k).
The next Klines consist of X+1 space-separated integers, where the first integer represents the count of choices of the th friend followed by X space-separated integers representing the fruits he likes.
The next line of the input consists of an integer - numN, representing the number of rows.
The next line of the input consists of an integer - numM, representing the number of columns.
Output
Print an integer representing the maximum number of friends he can make happy.
Input
The first line of the input consists of an integer - numOfFriends, representing the number of friends(k).
The next Klines consist of X+1 space-separated integers, where the first integer represents the count of choices of the th friend followed by X space-separated integers representing the fruits he likes.
The next line of the input consists of an integer - numN, representing the number of rows.
The next line of the input consists of an integer - numM, representing the number of columns.
Output
Print an integer representing the maximum number of friends he can make happy.
Constraints |
|
|
1 ≤ numN, numM ≤ 50 |
|
0 ≤ numOfFriends ≤ 3000 |
|
0 ≤ X≤ numN*numM |
|
1 ≤ i ≤ numOfFriends |
Example |
|
Input: |
|
3 |
|
3123 |
|
12 |
|
11 |
|
2 |
|
|
|
Output |
|
3 |
|
|
Explanation: |
|
In this example, a maximum of 3 |
|
friends can be made happy: |
|
Friend 1 gets fruit 3. |
|
Friend 2 gets fruit 2. |
|
Friend 3 gets fruit 1 |
Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 5 images