QOJ.ac

QOJ

时间限制: 2 s 内存限制: 1024 MB 总分: 10

#8408. 圖像 [C]

统计

Bajtazar 剛搬進新公寓。在用他從各種朗誦比賽和 Bajtocja 計時約德爾唱法錦標賽中贏得的獎盃裝飾好架子後,他發現有一面牆完全是空的。他對此感到不滿,因此想用畫作將其填滿。

Bajtazar 的牆是一個 $h \times w$ 公尺的矩形。他的一位熟識的畫商朋友提供了 $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

說明

範例說明:在第一個範例測試中,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.