Advanced Task 1 : Score attack
Don't worry, not all seniors can solve this too
Problem
Let's say a string is given to you containing only A's, B's, and C's, e.g. AACCBBCCCAAA. The objective is to eliminate all letters. Each turn, you can eliminate any consecutive letters that have the same value. For example, we can eliminate A, BB, and CCC; but not AC, BBC, and CAA.
One mark will be given for each letter eliminated. For example, if we eliminated BB in the above example, 2 marks will be given.
In addition, you can get a combo score by eliminating 5 or more letters at a time, determined by a combo multiplier. For instance, after eliminating BB, the remaining string will become AACCCCCAAA. If we eliminate CCCCC, 5×1.5=7.5 marks will be given. The combo multiplier table is shown below:
5
1.5
6
1.6
7
1.7
8
1.8
9
1.9
10
2.0
11
2.1
12
2.2
13
2.3
14
2.4
15
2.5
16
2.6
17
2.7
18
2.8
19
2.9
20
3.0
21
3.1
22
3.2
23
3.3
24
3.4
25
3.5
26
3.6
27
3.7
28
3.8
29
3.9
30+
4.0
If the eliminated length is greater than 30, the combo multiplier will still be 4.0.
Part 1
Your task is to write a program to find the maximum score obtainable by eliminating letters in the above fashion.
Example
Assumptions for this part
The input for "show intermediate steps" accepts both lowercase and uppercase letter.
The input string only has 'A', 'B', 'C', and nothing else.
The maximum length of the input string is 300.
Note: ZINC has a 5 seconds timeout. So, your code must finish running within 5 seconds
Part 2
Apart from finding the maximum score, please also output the steps of eliminating the letters.
Example
Assumptions
The input for show intermediate steps accept both lowercase and uppercase letter.
Some assumption is goneThe maximum length of the input string is 300.
When you have multiple choices to eliminate the letters, you should eliminate the string in the front first.
The output format of the steps is:
Note: ZINC has a 5 seconds timeout. So, your code must finish running within 5 seconds
Last updated