luogu#P9495. 「SFCOI-3」进行一个魔的除 I
「SFCOI-3」进行一个魔的除 I
Background
At last, the warrior defeats the Demon King and traps him in a room with no way out.
The Demon King can move freely in the dark, so the warrior can only find him and destroy him completely by turning on all the lights in the room.
Problem Description
There are lights in the room. The initial state is represented by , where means the light is initially off, and means the light is initially on.
Starting from the morning of day 1, the Demon King and the warrior take turns to act:
- Every morning, the Demon King may choose two consecutive lights and set both of their states to .
- Every night, the warrior may choose up to three arbitrary lights and set all of their states to .
For each action, the states of the chosen lights before being set can be anything.
Assume both sides use optimal strategies and will not make any move that is disadvantageous to themselves. The warrior wants to know the minimum number of days (that is, the minimum number of his operations) needed to set all lights to —only then can he catch the hateful Demon King and marry the beautiful princess.
Input Format
The first line contains an integer , the number of test cases.
For each test case:
- The first line contains an integer , the total number of lights.
- The second line contains numbers, in order, representing .
Output Format
For each test case, output one integer per line, the minimum number of days needed for the warrior to catch the Demon King.
In particular, if the warrior does not need to do any operation, output .
4
5
1 0 1 0 1
5
1 0 0 1 1
9
0 0 0 0 0 0 0 0 0
13
0 1 0 0 1 0 1 0 0 0 0 0 0
1
2
5
8
Hint
Sample Explanation 1
- On the morning of day 1, the Demon King turns off lights .
- On the night of day 1, the warrior turns on lights .
Sample Explanation 2
- On the morning of day 1, the Demon King turns off lights .
- On the night of day 1, the warrior turns on lights .
- On the morning of day 2, the Demon King turns off lights .
- On the night of day 2, the warrior turns on lights .
Constraints
This problem uses bundled testdata.
- Subtask 0 (10 points): , .
- Subtask 1 (30 points): .
- Subtask 2 (10 points): Initially, all lights are off.
- Subtask 3 (20 points): The testdata is randomly generated.
- Subtask 4 (30 points): No special restrictions.
For all testdata, , , .
Translated by ChatGPT 5