Algorithms – Problem 1 – Shooting Range (Solution)

$ 20.99

Description

You are given targets, each with a value to aim for. Each target can be hit only once. Consecutive hits increment a multiplier that initially starts at 1. Note that you are not allowed to miss in order to reset the multiplier. A hit on a target gives points equal to the target value multiplied by the current multiplier. Print all unique ways to achieve a given score from the targets.
Input
• On the first input line you will be given the the targets with their values.
Output
• Print all unique sequences of target hits that sum up to the score to achieve. Constraints
• The count of targets will be an integer in the range [1…15].
• Each target value will be an integer in the range [1…5].
• Score to achieve will be an integer in the range [1…1000].
• Time limit: 100 ms. Allowed memory: 32 MB.
Examples
Input Output Comment
1 2 3
10 3 2 1 The initial multiplier is 1. Consecutive hits increment it by 1.

(3 * 1) + (2 * 2) + (1 * 3) = 10

Input Output Comment
1 2 3 4 5
10 2 4
3 2 1
4 3 (2 * 1) + (4 * 2) = 10 (3 * 1) + (2 * 2) + (1 * 3) = 10 (4 * 1) + (3 * 2) = 10

Input Output Comment
1 1 1
4 Score of 4 cannot be achieved.

Reviews

There are no reviews yet.

Be the first to review “Algorithms – Problem 1 – Shooting Range (Solution)”

Your email address will not be published. Required fields are marked *