Dart Challenge
Time limit1sMemory limit128 MB
For each dartboard, count how many distinct total scores k darts can produce, where each dart misses or scores s_i, 2s_i, or 3s_i (no triple on the top area).
- Level
Medium4 of 10
- Topics
- Dynamic programming, Array, Combinatorics, Implementation
- Solved
- No attempts yet
Problem
Clark and Harry are siblings. As they had been rivals since early childhood, their father decided that each should focus on a different sport once they turned thirteen, so they would not have to compete for success. Now both are twenty and excel in different fields: Clark plays chess, while Harry competes in dart tournaments.
Having won three tournaments in a row, Harry started teasing Clark for not being as successful. Clark retorted that chess is less luck-based and therefore harder. Offended, Harry replied that playing darts optimally requires a great deal of combinatorics. Clark returned an icy smile and remarked that memorizing every possible late-game could hardly be called "combinatorics."
That is how the wager began. Harry bets that he can find all possible late-game scores for generalized dartboards on which memorized late-games are of no help. When Clark showed him a list of possible dartboards, Harry had to admit that he had probably bitten off more than he could chew. As his friend, you have to help him!
A dartboard consists of several areas. Each area has a score assigned for hitting it. Each area also has a double field and a triple field, worth twice and three times the area's score. The only exception is the area with the highest score: it has only a double field and no triple field. Given the scores of the areas, find the number of distinct total scores obtainable with a given number of darts.
A single dart throw scores one of the following:
- if the board is missed
- for hitting the single of some area
- for hitting the double of some area
- for hitting the triple of some area , except the highest-scoring area
Throwing darts, the total score is the sum of the individual dart scores (a missed dart adds ). Count how many distinct totals can be produced.
Input
The first line contains an integer . Each of the following lines contains one test case.
Each test case starts with two integers and (, ), the number of areas on the dartboard and the number of darts. Then integers follow (), where is the score for hitting area . All scores are distinct.
Remember that each area has a double field, and every area except the highest-scoring one also has a triple field. It is always possible to score with any dart by not hitting the board.
Output
For each test case, first output a line of the form Scenario #i:, where is the scenario number counting from . On the next line, output the number of distinct total scores obtainable with darts on the given board. Separate the outputs of different test cases with a single blank line.