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 |
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 5 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Concepts of Database Management](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)