If you can now make up 1...x of face value, plus a x+1 face value of banknotes, you can make up 1 ... x + C * (x + 1) face value.
because if the face value is K < (c+1) * (x + 1), we can use K/(x + 1) sheet The x+1 denomination of the banknotes, and the original notes made of K (x + 1), the k is obtained.
It is optimal to add a note that cannot be represented at the minimum value each time.
Problem
Up until today, the nation your live in have usedDDifferent positive integer denominations of coin for all transactions. Today, the Queen got angry when a subject tried to pay he taxes with a giant sack of low-valued coins, and she just Decre Ed that no more thanCCoins of any one denomination is used in any one purchase. For instance, ifC= 2 and the existing denominations is 1 and 5, it's possible to buy something of value all by using the 5s and one 1, or Something of value, by using the 5s and the 1s, but it's impossible to buy something of value 9 or 17.
You cannot directly challenge the Queen's decree, but do happen to being in charge of the mint, and youcanIssue new denominations of coin. Do it possible for want anyItem of positive value at the mostVTo be purchased under the Queen ' s new rules. (Note that this could not necessarily has been possible before the Queen ' s decree.) Moreover, want to introduce as few new denominations as possible, and your final combined set of pre-existing and new Denominations May is not having any repeats.
What is the smallest number of new denominations required?
Input
The first line of the input gives the number of test cases, T. T test Cases follow. Each consists of one line with three space-separated values C, D, and V, followed by another Li NE 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 th e 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
case #1:0Case #2:1Case #3:1Case #4:3
input |
output |
41 2 3 2 1 331 6 1001 5" |
| style= padding:0px 1em ; Vertical-align:top; Border-collapse:collapse; border-width:0pt; margin:0px ">
Note that Cases #3 and #4 is not within the limits for the Small dataset.
in case #1, it's already possible to make all the required values (1, 2, and 3) using at the most one copy 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 R equired.
in case #3, the optimal solution are 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 Round 1C C. Less money, more problems