QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 1024 MB Total points: 10

#8408. 图像 [C]

Statistics

Bajtazar 刚刚搬进了新公寓。在用他从各种朗诵比赛和 Bajtocja 约德尔唱法计时赛中获得的奖杯装饰好架子后,他发现有一面墙完全是空的。他不喜欢这样,所以想用画作把墙填满。

Bajtazar 的墙是一个 $h \times w$ 米的矩形。附近的一位画商是 Bajtazar 的好朋友,他提供 $n$ 种画作,且每种画作的数量都是无限的。同一种类的画作尺寸完全相同——第 $i$ 种画作总是边长为 $d_i$ 米的正方形。有趣的是,对于任意两个不同的 $d_i$ 值,其中一个总是能被另一个整除。

对于 Bajtazar 来说,画作的价格并不重要(毕竟约德尔唱法计时赛的奖金相当丰厚),但他想确保墙上不会留下任何空白。为此,他决定购买一定数量的画作,并将它们挂在墙上以完全覆盖墙面。当然,画作之间不能重叠,但它们可以边对边接触。Bajtazar 不想在画商那里往返太多次——所以他想购买尽可能少数量的画作。请帮助他编写一个程序,计算他最少需要购买多少幅画,或者判断是否无法覆盖墙面!

输入格式

第一行包含两个整数 $h$ 和 $w$ ($1 \le h, w \le 10^9$),表示 Bajtazar 墙面的尺寸。

第二行包含一个整数 $n$ ($1 \le n \le 30$),表示画作的种类数。

第三行包含一个由 $n$ 个不同整数组成的序列 $d_1, d_2, \dots, d_n$ ($1 \le d_i \le 10^9$; $d_i < d_{i+1}$; $d_{i+1}$ 能被 $d_i$ 整除),表示各类型画作的尺寸。

输出格式

如果能够覆盖墙面,则输出一行,包含一个整数,表示覆盖墙面所需的最少画作数量。否则,输出 $-1$。

样例

样例输入 1

6 10
3
1 3 6

样例输出 1

9

样例输入 2

3 3
1
2

样例输出 2

-1

说明

样例 1 说明:在第一个样例测试中,Bajtazar 可以用九幅画覆盖墙面(六幅 $1 \times 1$ 的,两幅 $3 \times 3$ 的,以及一幅 $6 \times 6$ 的),例如按以下方式排列:

在第二个样例测试中,无法精确覆盖墙面。

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.