GCJ 2015 Round 1C C. Less Money, More Problems

來源:互聯網
上載者:User

標籤:

如果現在能夠組成1...x 的面值,加上一種 x+1 面值的紙幣,就能組成 1 ... x + C * (x + 1)的面值。

因為如果面值是 k < (C+1)*(x + 1),我們可以用 k / (x + 1) 張 x+1 面值的紙幣,並用原來的紙幣組成 k % (x + 1),就得到了 k 。

每次添加不能被表示的最小面值的紙幣是最優的。

Problem

Up until today, the nation you live in has used D 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 C coins of any one denomination may be used in any one purchase. For instance, if C = 2 and the existing denominations are 1 and 5, it is possible to buy something of value 11 by using two 5s and one 1, or something of value 12 by using two 5s and two 1s, but it is impossible to buy something of value 9 or 17.

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 anyitem of positive value at most V 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?

Input

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

Output

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

Limits

1 ≤ T ≤ 100.
Each existing denomination ≤ V.

Small dataset

C = 1.
1 ≤ D ≤ 5.
1 ≤ V ≤ 30.

Large dataset

1 ≤ C ≤ 100.
1 ≤ D ≤ 100.
1 ≤ V ≤ 109.

Sample

Input 
 

Output 
 
41 2 31 21 3 61 2 52 1 331 6 1001 5 10 25 50 100
Case #1: 0Case #2: 1Case #3: 1Case #4: 3
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 (1, 2, and 3) using at most one copy of each of the existing denominations.

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

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

#include <bits/stdc++.h>using namespace std;#define prt(k) cerr<<#k" = "<<k<<endltypedef long long ll;#define SZ(v) ((int)(v).size())const int inf = 0x3f3f3f3f;#define For(i,n) for(int i=0;i<n;i++)#define SZ(v) ((int)(v).size())#define pb push_back#define ALL(v) (v).begin(), (v).end()#define Fill(a,b) memset(a,b,sizeof(a))#define foreach(i, v) for (__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++ i)int n, m;int main(){    int re ,ca=1; cin>>re;    while (re--) {        int C, D, V;        cin>>C>>D>>V;        vector<int> tmp;        int ans = 0;        ll x = 0;        for (int i =0;i<D;i++) {            int a; cin>>a;            while ( a - 1 > x )            {                x = x + 1ll * C * (x + 1);                ans ++;            }            x = x + 1ll * C * a;        }        while (x < V)        {            x = x + 1ll * C * (x + 1);            ans ++;        }        printf("Case #%d: ", ca++);        cout<<ans<<endl;    }}


GCJ 2015 Round 1C C. Less Money, More Problems

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.