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

如果现在能够组成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

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
Case #1: 0
Case #2: 1
Case #3: 1
Case #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<<endl
typedef 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;
    }
}
时间: 2024-10-24 08:39:51

GCJ 2015 Round 1C C. Less Money, More Problems的相关文章

GCJ 2015 Round 1C B. Typewriter Monkey

用最多需要的香蕉数减去目标串出现的概率就行啦.... 如何求出现的概率? 每个字符出现的概率乘起来--再乘以目标串能摆的位置个数-- Problem Your publishing house has decided to use monkeys randomly typing at keyboards to write great works of literature. You are the supervisor for one monkey with a keyboard contain

GCJ 2009 Round 1C Bribe the Prisoners

Bribe the Prisoners no tags     Problem In a kingdom there are prison cells (numbered 1 to P) built to form a straight line segment. Cells number i and i+1 are adjacent, and prisoners in adjacent cells are called "neighbours." A wall with a wind

TCO 2014 Round 1C 概率DP

TCO round 1C的 250 和500 的题目都太脑残了,不说了. TCO round 1C 950 一个棋子,每次等概率的向左向右移动,然后走n步之后,期望cover的区域大小?求cover,肯定就是dp[l][r][n], 走了n步之后,左边cover了l,右边cover了r. 一开始DP没有搞清楚,这个要画一下图就更清楚了. 转移方程就是概率的传递方向. 1: double dp[505][505][2]; // l,r,n steps unsed; 2: class RedPain

Google Code Jam 2009, Round 1C C. Bribe the Prisoners (记忆化dp)

Problem In a kingdom there are prison cells (numbered 1 to P) built to form a straight line segment. Cells number i and i+1 are adjacent, and prisoners in adjacent cells are called "neighbours." A wall with a window separates adjacent cells, and

GCJ Round 1C 2016 题解

ASenate Evacuation B Slides C Fashion Police A.Senate Evacuation #include<bits/stdc++.h> using namespace std; #define For(i,n) for(int i=1;i<=n;i++) #define Fork(i,k,n) for(int i=k;i<=n;i++) #define Rep(i,n) for(int i=0;i<n;i++) #define For

Facebook Hacker Cup 2015 Round 1--Corporate Gifting(树形动态规划)

原题:https://www.facebook.com/hackercup/problems.php?pid=759650454070547&round=344496159068801 题意:给定一颗有根树,在树上下层的节点要给上层节点礼物,根节点的礼物则给慈善会,但是给礼物有个条件就是你不能送你的父节点已经送出的礼物.问满足要求的最少花费. 题解:这个题卡了一段时间,类似于染色问题,可以用树形动态规划求解.因为已知节点个数为N,则我们单个节点的最大花费不会超过log2(N) = 18. 1.

hacker cup 2015 Round 1 解题报告

A:求区间内素因子个数等于n的数有多少个 解题思路:筛法 解题代码: 1 // File Name: a.cpp 2 // Author: darkdream 3 // Created Time: 2015年01月18日 星期日 13时54分20秒 4 5 #include<vector> 6 #include<list> 7 #include<map> 8 #include<set> 9 #include<deque> 10 #include&

Facebook Hacker Cup 2015 Round 1--Winning at Sports(动态规划)

原题:https://www.facebook.com/hackercup/problems.php?pid=688426044611322&round=344496159068801 题意:你和一个朋友玩足球游戏,分数从0-0开始,最终你总是赢,并且你主要有两种方式赢,第一种stressFree方式你肯定要进第一个球并且总是比你的朋友分数高,第二种stressFull方式除了你的朋友达到最终分数时,在游戏中你不可能比你的朋友分数高.给出一个比分,请分别输出在两种情况下你能赢的方式. 题解:类似

Google Code Jam 2015 Round 1A Mushroom Monster 水

题意:每10秒扫描一下盘子,查看盘子里面的面包个数,问你主角用两种吃法可能吃得的最少的面包. 1)任意吃. 2)每秒以恒定速度. 解题思路:暴力,找差值. 解题代码: 1 // File Name: a.cpp 2 // Author: darkdream 3 // Created Time: 2015年04月18日 星期六 09时52分04秒 4 5 #include<vector> 6 #include<list> 7 #include<map> 8 #includ