Darts
Time limit1sMemory limit128 MB
Count unordered triples of dart hits (single, double, treble regions, bulls, or misses) whose scores sum to a given turn score.
- Level
Medium4 of 10
- Topics
- Brute force, Implementation, Hash map, Combinatorics
- Solved
- No attempts yet
Problem
Many nations (including Germany) have an old tradition of throwing small arrows at round, flat targets. Both the small arrows and the game itself are called darts.
A dartboard is a single flat circle divided into slices and rings. The slices are numbered from 1 to 20, and the two outer rings are called the double ring and the treble ring. The center of the board is the bull's eye, which is split into an inner part (the real bull's eye) and an outer part (called the bull).

Figure: Layout of a dartboard.
Scoring works as follows. If you hit slice number , a single (the plain region) scores , the double ring scores , and the treble ring scores . For example, hitting slice 20 in the double ring scores 2 × 20 = 40. The inner part of the bull's eye counts 50, and the outer part (the bull) counts 25. A dart that misses the board and hits no region scores 0.
A turn consists of throwing 3 darts, and the score of the turn is the sum of the scores of the three darts.
Yesterday your friends played darts, and the scores are still on the blackboard. From the score of each turn alone, you would like to know which regions the three darts could have hit. Given the total score of a turn, write a program that counts the number of distinct combinations of three dart hits that produce that score. The order in which the darts are thrown does not matter.
Two combinations are considered the same based on the regions hit: two darts are the same only if they hit the same slice in the same ring, or hit the same bull, or both miss. Darts with the same value but different regions (for example, a single 3 and a treble 1) count as different.
For example, a turn score of 3 can be formed in the following ways:
3 = 0 + 0 + 1*3 one dart hits slice 3
3 = 0 + 0 + 3*1 one dart hits slice 1 in the treble ring
3 = 0 + 1*1 + 1*2 one dart hits slice 1, one dart hits slice 2
3 = 0 + 1*1 + 2*1 one dart hits slice 1, one dart hits slice 1 in the double ring
3 = 1*1 + 1*1 + 1*1 all three darts hit slice 1
So the number of distinct combinations is 5.
A more complex example, the score 9, includes combinations such as:
9 = 0 + 0 + 1*9 one dart hits slice 9
9 = 0 + 0 + 3*3 one dart hits slice 3 in the treble ring
9 = 0 + 1*1 + 1*8 one dart hits slice 1, one dart hits slice 8
9 = 0 + 1*1 + 2*4 one dart hits slice 1, one dart hits slice 4 in the double ring
...
9 = 0 + 3*2 + 1*3 one dart hits slice 2 in the treble ring, one dart hits slice 3
9 = 1*1 + 1*1 + 1*7 two darts hit slice 1, one dart hits slice 7
...
9 = 2*1 + 3*1 + 2*2 slice 1 double, slice 1 treble, slice 2 double
9 = 1*3 + 1*3 + 1*3 all three darts hit slice 3
9 = 1*3 + 1*3 + 3*1 two darts hit slice 3, one dart hits slice 1 in the treble ring
9 = 1*3 + 3*1 + 3*1 one dart hits slice 3, two darts hit slice 1 in the treble ring
9 = 3*1 + 3*1 + 3*1 all three darts hit slice 1 in the treble ring
What is the number of combinations? Write a program to find out.
Input
The first line contains the number of scenarios (turns).
Each of the following lines contains one scenario: the dart score of that turn, given as a single positive integer.
Output
For each scenario, first print a line of the form "Scenario #i:", where is the scenario number starting from 1. On the next line, print the number of distinct dart combinations that produce that score.
Separate the output of two consecutive scenarios with a single blank line.