QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 2048 MB Total points: 100

#10474. Ribbon on the Christmas Present

統計

你正在准备一条丝带用来装饰圣诞礼盒。你计划将原本白色的丝带染成不同深浅红色的条纹图案。丝带由若干个部分组成,每个部分都需要按照计划进行染色。

你希望用最少的染色次数来准备这条丝带。丝带的连续部分可以用同一种深浅的红色染料一次性染成。已经染过某种深浅红色的丝带部分可以用更深颜色的染料覆盖染色;覆盖后,该部分将呈现那种更深的颜色。但是,不允许用较浅的颜色进行覆盖染色。由于丝带最初是白色的,所有部分都必须至少染色一次。

图 A.1. 样例输入 1 的条纹图案

图 A.1 展示了样例输入 1 的图案。丝带共有六个部分,部分中的数字表示要染成的深浅级别。数字越大表示颜色越深。这可以通过三次染色步骤完成:

  1. 用深浅级别为 50 的红色染料染整条丝带,
  2. 用深浅级别为 100 的较深染料染从左往右数第二个部分,然后
  3. 用深浅级别为 100 的染料染第五个部分。

编写一个程序,计算出制作该计划条纹图案所需的最少染色步骤数。

输入格式

输入包含一个测试用例,格式如下:

$n$ $d_1 \ d_2 \ \dots \ d_n$

测试用例以一个整数 $n$ ($1 \le n \le 100$) 开头,表示丝带的部分数量。第二行包含 $n$ 个整数 $d_1, d_2, \dots, d_n$,描述了 $n$ 个部分计划的深浅级别。其中,$d_i$ 表示第 $i$ 个部分计划的深浅级别,取值在 1 到 100 之间(包含 1 和 100),数值越大表示颜色越深。

输出格式

输出一行,包含制作该计划条纹图案所需的最少染色步骤数。

样例

输入 1

6
50 100 50 50 100 50

输出 1

3

输入 2

5
1 2 3 2 1

输出 2

3

输入 3

5
3 2 1 2 3

输出 3

5

输入 4

10
1 20 100 1 20 20 100 100 20 20

输出 4

5

输入 5

5
10 60 100 30 10

输出 5

4

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.