
Description
There is an integer array A1, A2 …AN. Each round you may choose two adjacent integers. If their sum is an odd number, the two adjacent integers can be deleted.
Can you work out the minimum length of the final array after elaborate deletions?
Input
The first line contains one integer N, indicating the length of the initial array.
The second line contains N integers, indicating A1, A2 …AN.
For 30% of the data:1 ≤ N ≤ 10
For 60% of the data:1 ≤ N ≤ 1000
For 100% of the data:1 ≤ N ≤ 1000000, 0 ≤ Ai ≤ 1000000000
Output
One line with an integer indicating the minimum length of the final array.
Sample Hint
(1,2) (3,4) (4,5) are deleted.
Sample Input
7
1 1 2 3 4 4 5
Sample Output
1
2. Analysis
观察到只要有一个奇数,这个奇数和之前的所有连续偶数都可以一同消去。
3. Solution(s)
Brute-Force solution:
|
|
A better one:
|
|




近期评论