Created
April 25, 2014 11:19
-
-
Save linggom/11286094 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Problem Statement | |
Cat Taro has N cards. Exactly two integers are written on each card. You are given two int[]s first and second, each with N elements. For each i, the element first[i] represents the first integer on the i-th card, and the element second[i] represents the second integer on the i-th card. | |
It is known that for each x from 1 to N, inclusive, there is exactly one card with the first integer equal to x. In other words, all elements of first represent a permutation of integers from 1 to N, inclusive. On the other hand, second may contain duplicates, but all elements of second are only between 1 and 10, inclusive. | |
You are also given an int K. Taro wants to choose some subset of the cards (possibly none or all of them) in such a way that the total number of different integers written on the cards is less than or equal to K. Return the total number of ways to do that. | |
Definition | |
Class: | |
TaroCards | |
Method: | |
getNumber | |
Parameters: | |
int[], int[], int | |
Returns: | |
long | |
Method signature: | |
long getNumber(int[] first, int[] second, int K) | |
(be sure your method is public) | |
Limits | |
Time limit (s): | |
2.000 | |
Memory limit (MB): | |
256 | |
Constraints | |
- | |
first will contain between 1 and 50 elements, inclusive. | |
- | |
first and second will contain the same number of elements. | |
- | |
first will represent a permutation of integers between 1 and N, inclusive, where N is the number of elements in first. | |
- | |
Each element of second will be between 1 and 10, inclusive. | |
- | |
K will be between 1 and 2N, inclusive, where N is the number of elements in first. | |
Examples | |
0) | |
{1, 2} | |
{2, 3} | |
2 | |
Returns: 3 | |
In this case, there are four subsets of cards: | |
None of the cards. The number of different integers is 0. | |
Only the first card. The number of different integers is 2. | |
Only the second card. The number of different integers is 2. | |
Both the first and the second card. The number of different integers is 3. | |
However, the last subset has too many different integers. Thus, the answer is 3. | |
1) | |
{3, 1, 2} | |
{1, 1, 1} | |
3 | |
Returns: 8 | |
2) | |
{4, 2, 1, 3} | |
{1, 2, 3, 4} | |
5 | |
Returns: 16 | |
3) | |
{1, 2, 3, 4, 5, 6, 7} | |
{2, 1, 10, 9, 3, 2, 2} | |
3 | |
Returns: 17 | |
4) | |
{1} | |
{2} | |
1 | |
Returns: 1 | |
5) | |
{6, 20, 1, 11, 19, 14, 2, 8, 15, 21, 9, 10, 4, 16, 12, 17, 13, 22, 7, 18, 3, 5} | |
{4, 5, 10, 7, 6, 2, 1, 10, 10, 7, 9, 4, 5, 9, 5, 10, 10, 3, 6, 6, 4, 4} | |
14 | |
Returns: 2239000 | |
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment