QOJ.ac

QOJ

시간 제한: 1 s 메모리 제한: 1024 MB 총점: 100 해킹 가능 ✓

#17934. 制作巧克力树

통계

Coco 想要用巧克力玩一个建树游戏。每个巧克力上都写着一个介于 $0$ 到 $N-1$ 之间的整数。建树游戏是构建一棵二叉树,其中每个节点上都放置一个巧克力,游戏按如下方式进行:

  • 最开始,创建树的根节点,并放置一个写有任意整数的巧克力。
  • 之后,重复以下步骤:
    • 选择一个叶子节点。设该节点巧克力上的数字为 $M$。
    • 在选定的节点下方添加两个子节点,并选择两个和为 $M$ 或 $N+M$ 的数,将写有这两个数的巧克力放在这两个子节点上。

Coco 拥有无限多个写有数字 $a_1, a_2, \cdots, a_k$ 的巧克力,但没有写有其他数字的巧克力,因此必须向 Hanbyul 借。如果要构建一棵所有叶子节点的深度(到根节点路径上的边数)均为 $H$ 的树,求为了完成这棵树,Coco 最少需要向 Hanbyul 借多少个巧克力。

输入格式

第一行给出 $N$,$H$,$k$ 的值。($2 \le N \le 500$,$1 \le H \le 60$,$1 \le k \le N$)

第二行给出 $a_1, a_2, \cdots, a_k$ 的值。($0 \le a_i < N$)$a_i$ 的值互不相同。

输出格式

在一行中输出需要向 Hanbyul 借的巧克力的最少数量。

样例

输入样例 1

2 5 1
1

输出样例 1

21

输入样例 2

3 5 2
1 2

输出样例 2

0

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.