Files
luogu/CF1312E.md
T
hanyixuanten 4fb89722a1
Check cpp / md pair / Check md headers (push) Failing after 0s
new file: CF1312E.cpp
2026-10-26 12:32:30 +00:00

89 lines
1.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# CF1312E Array Shrinking
## 题目描述
给你一个长度为 $n(1 \le n \le 500)$ 的数组 $a$,每次你可以进行以下两步操作:
1. 找到 $i \in [1, n)$,使得 $a_i = a_{i + 1}$;
2. 将 **它们** 替换为 $a_i + 1$。
每轮操作之后,显然数组的长度会减小 $1$,问剩余数组长度的最小值。
## 输入格式
第一行包含一个整数 $n(1 \le n \le 500)$,表示数组的原长。
第二行包含 $n$ 个整数 $a_1, a_2, \cdots a_n (1 \le a_i \le 1000)$,表示原数组 $a$。
## 输出格式
共一行仅一个整数 $num$,表示进行许多轮操作之后,$a$ 剩余长度的最小值。
### 样例解释
第一组样例中,最优操作之一为 $\text{4 3 2 2 3} \to \text{4 3 3 3} \to \text{4 4 3} \to \text{5 3}$
第二组样例中,最优操作之一为 $\text{3 3 4 4 4 3 3} \to \text{4 4 4 4 3 3} \to \text{4 4 4 4 4} \to \text{5 4 4 4} \to \text{5 5 4} \to \text{6 4}$
对于第三和第四组样例,你并不能进行任何操作。
## 输入输出样例 #1
### 输入 #1
```
5
4 3 2 2 3
```
### 输出 #1
```
2
```
## 输入输出样例 #2
### 输入 #2
```
7
3 3 4 4 4 3 3
```
### 输出 #2
```
2
```
## 输入输出样例 #3
### 输入 #3
```
3
1 3 5
```
### 输出 #3
```
3
```
## 输入输出样例 #4
### 输入 #4
```
1
1000
```
### 输出 #4
```
1
```