logo AlgoBeat OnlineJudge
登录 注册

#213340. [GCJ 2015 #1C] Less Money, More Problems

内存限制:1024 MiB 时间限制:10000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

Up until today, the nation you live in has used different positive integer denominations of coin for all transactions. Today, the queen got angry when a subject tried to pay his taxes with a giant sack of low-valued coins, and she just decreed that no more than coins of any one denomination may be used in any one purchase. For instance, if and the existing denominations are and , it is possible to buy something of value by using two s and one , or something of value by using two s and two s, but it is impossible to buy something of value or .

You cannot directly challenge the queen's decree, but you happen to be in charge of the mint, and you can issue new denominations of coin. You want to make it possible for any item of positive value at most to be purchased under the queen's new rules. (Note that this may not necessarily have been possible before the queen's decree.) Moreover, you want to introduce as few new denominations as possible, and your final combined set of pre-existing and new denominations may not have any repeats.

What is the smallest number of new denominations required?

输入格式

The first line of the input gives the number of test cases, . test cases follow. Each consists of one line with three space-separated values , , and , followed by another line with distinct space-separated values representing the preexisting denominations, in ascending order.

输出格式

For each test case, output one line containing "Case #: ", where x is the test case number (starting from ) and y is the minimum number of new denominations required, as described above.

样例

样例输入 1

4
1 2 3
1 2
1 3 6
1 2 5
2 1 3
3
1 6 100
1 5 10 25 50 100

样例输出 1

Case #1: 0
Case #2: 1
Case #3: 1
Case #4: 3

数据范围与提示

Sample Explanation

Note that Cases #3 and #4 are not within the limits for the Small dataset.

In Case #1, it is already possible to make all the required values (, and ) using at most one copy of each of the existing denominations.

In Case #2, it suffices to add a denomination of either or -- whichever you choose, only one new denomination is required.

In Case #3, the optimal solution is to add a denomination of .

Limits

  • .
  • Each existing denomination .

Small dataset(11 Pts)

  • Time limit: 240 5 seconds.
  • .
  • .
  • .

Large dataset(23 Pts)

  • Time limit: 480 10 seconds.
  • .
  • .
  • .