WinterAndCandies
SRM 601 · 2013-06-25 · by Witaliy
Problem Statement
It's winter time! You have some candies arranged in a row and now you want to choose some of them and give them to your friend.
You are given a
Notes
- The answer will always fit in a signed 32-bit integer.
Constraints
- type will contain between 1 and 50 elements, inclusive.
- Each element of type will be between 1 and 50, inclusive.
{1, 3, 2}
Returns: 3
There are 7 possible non-empty subsets in this case: (1) (3) (2) (1, 3) (1, 2) (3, 2) (1, 3, 2) Out of them, only first, fifth and seventh are valid. Thus, the answer is 3.
{1, 1, 2}
Returns: 4
Note that the chosen subset can never contain two elements with the same type.
{1, 3, 2, 5, 7, 4, 5, 4}
Returns: 9
{1, 1, 2, 2, 3, 3, 4, 4, 5, 5}
Returns: 62
{2}
Returns: 0
Submissions are judged against all 71 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class WinterAndCandies with a public method int getNumber(vector<int> type) · 71 test cases · 2 s / 256 MB per case