QOJ.ac

QOJ

実行時間制限: 1 s メモリ制限: 1024 MB 満点: 100 ハック可能 ✓

#18591. 阶乘攻击

統計

场地上一共有 $N$ 只怪物排成一列。 第 $i$ 只怪物的体力值为 $h_i$。

你需要消灭场地上的所有怪物。 要消灭一只怪物,必须将其体力值降至 $0$ 或以下。

为了消灭怪物,你可以选择两个整数 $l \le r$,对第 $l$ 只到第 $r$ 只怪物施放范围攻击。

受到该范围攻击的怪物,其体力值会减少 $(N - r + l)!$。

请计算为了消灭所有怪物,最少需要施放多少次范围攻击。

$n!$ 表示从 $1$ 到 $n$ 的所有整数的乘积。

输入格式

第一行包含一个整数 $N$。$(1 \le N \le 500)$

第二行包含 $h_1, h_2, \ldots, h_N$,以空格分隔。$(1 \le h_i \le 5000)$

输出格式

第一行输出消灭所有怪物所需的最少范围攻击次数。

样例

输入 1

4
1 2 3 4

输出 1

2

输入 2

1
5000

输出 2

5000

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.