CF1312E.Array Shrinking
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an array a1,a2,…,an . You can perform the following operation any number of times:
- Choose a pair of two neighboring equal elements ai=ai+1 (if there is at least one such pair).
- Replace them by one element with value ai+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≤n≤500 ) — the initial length of the array a .
The second line contains n integers a1,a2,…,an ( 1≤ai≤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
说明/提示
In the first test, this is one of the optimal sequences of operations: 4 3 2 2 3 → 4 3 3 3 → 4 4 3 → 5 3 .
In the second test, this is one of the optimal sequences of operations: 3 3 4 4 4 3 3 → 4 4 4 4 3 3 → 4 4 4 4 4 → 5 4 4 4 → 5 5 4 → 6 4 .
In the third and fourth tests, you can't perform the operation at all.