#P6496. [COCI 2016/2017 #2] Nizin
[COCI 2016/2017 #2] Nizin
Description
Let be an array with elements, indexed from . If for every integer we have , then is called a “palindrome array”.
Mislav can modify an array in the following way:
- Choose two adjacent elements.
- Replace these two elements with one new element whose value is their sum.
Now, an array is given. Please compute the minimum number of modifications needed for Mislav to turn it into a “palindrome array”.
Input Format
The first line contains an integer , the number of elements in the array.
The next line contains integers , the elements of the array.
Output Format
One line with one integer, the minimum number of modifications Mislav needs to make.
3
1 2 3
1
5
1 2 4 6 1
1
4
1 4 3 2
2
Hint
Sample Explanation
Use [] to mark the two numbers Mislav chooses in each modification.
Sample 1 Explanation
[1 2] 3 -> 3 3.
Sample 2 Explanation
1 [2 4] 6 1 -> 1 6 6 1.
Sample 3 Explanation
[1 4] 3 2 -> 5 [3 2] -> 5 5.
Constraints
- For of the testdata, .
- For of the testdata, .
- For of the testdata, , .
Note
Translated from COCI2016-2017 CONTEST #2 T3 Nizin。
Translated by ChatGPT 5
京公网安备 11011102002149号