#P11188. 「KDOI-10」商店砍价
「KDOI-10」商店砍价
Description
There is an integer consisting only of digits .
You can do an arbitrary number of operations on (possibly zero):
- Choose a digit of and delete it. Suppose the digit is , this operation will cost . Note that after this operation, the length of decreases by , and the value of also changes;
- Delete all the remaining digits of . This operation will cost .
Find the minimum cost to delete all digits of .
Input Format
Each test contains multiple test cases.
The first line of the input contains a single integer — the id of the test. represents that this is a sample test.
The second line contains a single integer — the number of test cases.
For each test case:
- The first line contains a single integer — the initial value of the integer.
- The second line contains nine integers — the cost of deleting each digit.
Output Format
For each test case:
- Print a single integer in the only line of the output — the minimum cost.
0
3
123
10 10 10 10 10 10 10 10 10
1121
2 1 2 2 2 2 2 2 2
987654321
1 2 3 4 5 6 7 8 9
21
6
45
Hint
Sample 1 Explanation
In the first test case, the optimal operations are:
- Delete digit with a cost of . After that, becomes ;
- Delete digit with a cost of . After that, becomes ;
- Delete all the remaining digits of with a cost of .
The total cost is . It can be shown that this is the minimum cost.
In the second test case, the optimal operations are:
- Delete the first digit with a cost of . After that, becomes ;
- Delete the last digit with a cost of . After that, becomes ;
- Delete digit with a cost of . After that, becomes ;
- Delete all the remaining digits of with a cost of .
The total cost is .
Sample 2
See bargain/bargain2.in and bargain/bargain2.ans in the attachments.
This sample satisfies the constraints of test .
Sample 3
See bargain/bargain3.in and bargain/bargain3.ans in the attachments.
This sample satisfies the constraints of test .
Sample 4
See bargain/bargain4.in and bargain/bargain4.ans in the attachments.
This sample satisfies the constraints of test .
Sample 5
See bargain/bargain5.in and bargain/bargain5.ans in the attachments.
This sample satisfies the constraints of test .
Constraints
For all the tests, it is guaranteed that:
- ;
- ;
- For each ,;
- consists only of digits .
| Test Id | Special Properties | ||
|---|---|---|---|
| - | |||
| consists of only one type of digits. | |||
| consists of at most two types of digits. | |||
| consists of at most three types of digits. | |||
| - | |||
京公网安备 11011102002149号