#P16279. 「MierOI R1」Future
「MierOI R1」Future
Problem Description
Given a -digit decimal number . It is guaranteed that is even, and .
You can perform the following operation exactly times:
- Delete any two adjacent digits in , and gain points. The remaining digits are automatically concatenated.
Find the maximum total score.
Input Format
This problem contains multiple test cases.
The first line of the input contains a positive integer , indicating the number of test cases.
Then, the test cases follow sequentially. For each test case:
- The first line contains a single positive integer .
- The second line contains a -digit decimal number .
Output Format
For each test case, output a single line containing an integer, representing the maximum total score.
3
4
2432
8
19919911
16
1991991119919911
65
292
656
Hint
Explanation for Sample #1
For the first test case, the optimal sequence of operations is as follows:
- Delete digits , gaining points. becomes .
- Delete digits , gaining points. becomes empty.
The total score is points. It can be proven that this is the maximum total score.
Data Range
This problem uses bundled subtasks.
For all test cases, it is guaranteed that , , and .
::cute-table{tuack}
| Subtask | Special Property | Score | |
|---|---|---|---|
| None | |||
| ^ | |||
| A | |||
| ^ | None |
- Special Property A: .