#P197. [Sleeping Cup #7] Rice Cake Consumption
[Sleeping Cup #7] Rice Cake Consumption
Person in Charge
Attention
The sample cases for this problem are not placed in subtask 0. Instead, they are located elsewhere:
| Sample | Data File | Subtask ID | Test Point |
|---|---|---|---|
| Sample 1 | 11.in / 11.out |
Subtask 2 | #2-1 |
19.in / 19.out |
Subtask 3 | #3-1 | |
| Sample 2 | 12.in / 12.out |
Subtask 2 | #2-2 |
Sample 1 will be judged twice.
The subtask dependencies are as follows:
| Subtask ID | Depends on |
|---|---|
| Subtask 1 | none |
| Subtask 2 | Subtask 1 |
| Subtask 3 | none |
| Subtask 4 | Subtasks 2 and 3 |
File I/O is required (ricecake.in / ricecake.out).
Problem Background
One evening, Sleeping Goose bought a skewer of rice cakes coated with chili sauce.
Problem Description
The bamboo skewer has positions for rice cakes, some of which are occupied (immovable) and some of which are empty.
Sleeping Goose wants to eat every rice cake in some order while minimizing the amount of chili sauce rubbed off.
When it decides to eat a rice cake, its beak touches all other rice cakes within at most positions of the chosen one.
Each time a rice cake is touched, unit of sauce is removed.
Compute the minimum total units of sauce that will be rubbed off under the best possible eating order.
Input Format
Multiple test cases.
First line: an integer , the number of test cases.
For each test case:
- First line: two integers .
- Second line: a 01-string of length , where
1indicates a rice cake at that position and0indicates no cake.
Output Format
For each test case, output one integer: the minimum total units of sauce rubbed off.
Samples
2
1 0
1
7 6
0000000
0
0
2
9 1
111010111
32 12
00110000100000000001000000110110
4
14
Sample 2 Explanation
For the first test case, an optimal eating order is:
- Eat the cake at position 5.
- Eat the cake at position 3; this touches the cake at position 2.
- Eat the cake at position 2; this touches the cake at position 1.
- Eat the cake at position 1.
- Eat the cake at position 8; this touches cakes at positions 7 and 9.
- Eat the cake at position 9.
- Eat the cake at position 7.
Data Range
For of the data: , , .
There are four equally-weighted subtasks:
- .
- .
- Guaranteed .
- No additional constraints.
相关
在下列比赛中: