#CF1479B1. Painting the Array I
Painting the Array I
Painting the Array I
题面翻译
题意
本题与 CF1480D2 的唯一区别是本题询问最大可能解.
给定一个数组 , 你将将 染为 色, 其中 是由你指定的一个 01 数组. 将 数组中被染成 0 色的数字取出来并依在 中出现的顺序排列, 组成数组 . 同理, 将 数组中被染成 1 色的数字取出来并依在 中出现的顺序排列, 组成数组 . 我们定义 是一个正整数, 其中 是一个数组, 的值为在我们将 中相邻的所有相同元素合并后, 数组的大小. 例如, . 最大化 .
输入格式
第一行包括一个正整数 .
第二行包括 个正整数 .
输出格式
仅输出一个正整数, 代表最大的 .
题目描述
The only difference between the two versions is that this version asks the maximal possible answer.
Homer likes arrays a lot. Today he is painting an array with two kinds of colors, white and black. A painting assignment for is described by an array that indicates the color of ( for white and for black).
According to a painting assignment , the array is split into two new arrays and , where is the sub-sequence of all white elements in and is the sub-sequence of all black elements in . For example, if and , then and .
The number of segments in an array , denoted , is the number of elements if we merge all adjacent elements with the same value in . For example, the number of segments in is , because the array will become after merging adjacent elements with the same value. Especially, the number of segments in an empty array is .
Homer wants to find a painting assignment , according to which the number of segments in both and , i.e. , is as large as possible. Find this number.
输入格式
The first line contains an integer ( ).
The second line contains integers ( ).
输出格式
Output a single integer, indicating the maximal possible total number of segments.
样例 #1
样例输入 #1
7
1 1 2 2 3 3 3
样例输出 #1
6
样例 #2
样例输入 #2
7
1 2 3 4 5 6 7
样例输出 #2
7
提示
In the first example, we can choose , and . So the answer is .
In the second example, we can choose and is empty. We can see that and . So the answer is .
Statistics
Related
In following homework: