#P2438. [SDOI2005] 解环
[SDOI2005] 解环
Description
To help Baitesa! The rings on the chain are numbered . We can detach them according to the following rules:
- At each step, you may attach or detach exactly one ring to or from the fence.
- Ring can always be attached or detached.
- If rings are all detached and ring is attached, where , then you may attach or detach ring .
Write a program that, given the description of the Byte Chain, computes the minimum number of operations needed to remove all rings from the fence and outputs the result.
Input Format
The first line contains an integer , where .
The second line contains integers (each is or ) separated by single spaces. If , then the -th ring is attached to the fence; if , then the -th ring is not attached.
Output Format
Output a single integer: the minimum number of operations required to detach all rings from the fence.
4
1 0 1 0
6
Hint
Translated by ChatGPT 5
京公网安备 11011102002149号