题库练习 Array Shrinking
← 上一题 下一题 →

A13344 | Array Shrinking

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

You are given an array $a_1, a_2, \dots, a_n$ . You can perform the following operation any number of times:

- Choose a pair of two neighboring equal elements $a_i = a_{i + 1}$ (if there is at least one such pair).
- Replace them by one element with value $a_i + 1$ .

After each such operation, the length of the array will decrease by one (and elements are renumerated accordingly). What is the minimum possible length of the array $a$ you can get?

输入格式

The first line contains the single integer $n$ ( $1 \le n \le 500$ ) — the initial length of the array $a$ .

The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ( $1 \le a_i \le 1000$ ) — the initial array $a$ .

输出格式

Print the only integer — the minimum possible length you can get after performing the operation described above any number of times.

输入输出样例

输入 #1
5
4 3 2 2 3
输出 #1
2
输入 #2
7
3 3 4 4 4 3 3
输出 #2
2
输入 #3
3
1 3 5
输出 #3
3
输入 #4
1
1000
输出 #4
1
C++ 编辑器
输入
输出