【hdu 5527】 [2015ACM/ICPC亚洲区长春站] Too Rich 贪心

限时加码!20+主流AI编程工具免费用 购周边加赠Coding Plan Lite,Claude Code、Cursor等即刻畅享,学习进阶更高效! 阅读详情

Too Rich
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 673 Accepted Submission(s): 173

Problem Description
You are a rich person, and you think your wallet is too heavy and full now. So you want to give me some money by buying a lovely pusheen sticker which costs p dollars from me. To make your wallet lighter, you decide to pay exactly p dollars by as many coins and/or banknotes as possible.

For example, if p=17 and you have two 10coins,four 5 coins, and eight 1coins,youwillpayitbytwo 5 coins and seven $1 coins. But this task is incredibly hard since you are too rich and the sticker is too expensive and pusheen is too lovely, please write a program to calculate the best solution.

Input
The first line contains an integer T indicating the total number of test cases. Each test case is a line with 11 integers p,c1,c5,c10,c20,c50,c100,c200,c500,c1000,c2000, specifying the price of the pusheen sticker, and the number of coins and banknotes in each denomination. The number ci means how many coins/banknotes in denominations of i dollars in your wallet.

1≤T≤20000
0≤p≤109
0≤ci≤100000

Output
For each test case, please output the maximum number of coins and/or banknotes he can pay for exactly p dollars in a line. If you cannot pay for exactly p dollars, please simply output ‘-1’.

Sample Input

3
17 8 4 2 0 0 0 0 0 0 0
100 99 0 0 0 0 0 0 0 0 0
2015 9 8 7 6 5 4 3 2 1 0

Sample Output

9
-1
36

Source
2015ACM/ICPC亚洲区长春站
题目链接
http://acm.hdu.edu.cn/showproblem.php?pid=5527

题意
选出凑成N的最多的钱数;

思路
从大面值到小面值贪心,剩下的只要可以被取到便取最少的大面值的;因为500,200等非倍数的存在,
反例:150,用50,20取,故取时500,50,等可能多取一个即可;

代码

#include<iostream>
#include<stdio.h>
using namespace std;
int v[11]={0,1,5,10,20,50,100,200,500,1000,2000};
int s[11];
int ans;int N;
long long T[11];
void dfs(int p,int n,int d)
{

    if(p<0) return ;
    if(d==0)
    {
        if(!p)
        ans=max(ans,n);
        return ;
    }
    long long tmp=max((long long)0,p-T[d-1]);
    int k=tmp/v[d]+(tmp%v[d]?1:0);

    if(k>s[d]) return ;
    dfs(p-k*v[d],k+n,d-1);

    k++;
    if(k<=s[d])
    dfs(p-k*v[d],k+n,d-1);
}

int main()
{
    int c;
    scanf("%d",&c);
    while(c--)
    {
        scanf("%d",&N);
        for(int i=1;i<=10;i++)
        scanf("%d",&s[i]);
        T[0]=0;
        for(int i=1;i<=10;i++)
        {
            T[i]=T[i-1]+(long long)s[i]*(long long)v[i];
        }
        ans=0;
        dfs(N,0,10);

        if(!ans) printf("-1\n");
        else printf("%d\n",ans);
    }

}
F460 CLK配置功能模块说明 F460CLK配置功能模块说明 目录 F460CLK配置功能模块说明 CLK配置: 1. DDL_ICG——初始化配置 2. DDL_UTILITY——基础功能函数 3.DDL_PRINT-待细化 4.DDL_ADC 5.DDL_AES——AES 加解密算法处理器 6.DDL_CAN 7. DDL_CLK 8. DDL_CMP——电压比较器 9. DDL_CRC 10. DDL_DCU——数据计算单元 11. DDL_DMAC——DMA 控制器 ... 阅读详情

相关推荐

YOLO11涨点优化:卷积魔改 | DCNv2升级版本,助力检测

在DCN的基础上,增加了2个创新点,分别是调制模块和使用多个调制后的DCN模块,从形成了DCN的升级版本——DCNv2

①答疑群聊服务;②YOLO大模型知识问答系统;③计算机视觉论文生成智能体; 931

有关乱码的处理---中国程序员永远无法避免的话题

为什么说乱码是中国程序员无法避免的话题呢?这个首先要从编码机制上说起,大家都是中文和英文的编码格式不是一样,解码也是不一样的!如果中国的程序员不会遇到乱码,那么只有使用汉语编程。汉语编程是怎么回事我也不大清楚,应该是前年吧,我一朋友给我介绍汉语编程,怎么不错不错?当时因为学习忙没去关注这个,等我闲了,那个朋友不弄这个,问他他也不说不大清楚,最后自己对这个学习也不了了之了。    今天我写这个不是讲...

sodabao 552

整理 钢琴 约翰汤普森-简易钢琴(小汤)

文件名:(小汤1)约翰-汤普森钢琴1 超清PDF (原版引进)文件名:(小汤2)约翰-汤普森钢琴2 超清PDF (原版引进)文件名:(小汤3)约翰-汤普森钢琴3 超清PDF (原版引进)文件名:(小汤4)约翰-汤普森钢琴4 超清PDF (原版引进)文件名:(小汤5)约翰-汤普森钢琴5 超清PDF (原版引进)文件大小:20.1 MB。文件大小:23.7 MB。文件大小:45.7 MB。文件大小:51.7 MB。文件大小:72.0 MB。

TS的博客 5万+

100条经典C++笔试题目及答案分享

100条经典C++笔试题目分享一、C++与C差异(1-18)二、数据类型、关键字(19-37)三、C++面向对象的特性(38-61)四、程序阅读题(62-90)五、编程练习(91-100) 看到好用的经典C++题目,对机试和笔试,甚至面试都有帮助,特意分享,自己也复习一遍,互勉。 题目来源: 1、中兴、华为、慧通、英华达、微软亚洲技术中心等中外企业面试题目; 2、C++面试宝典(林锐《高质量编程第...

Penn Li的博客 8万+

HDU-5527 Too Rich (逆向思维+贪心,两种做法)

题目链接:https://vjudge.net/problem/HDU-5527 Too Rich You are a rich person, and you think your wallet is too heavy and full now. So you wa...

weixin_44757834的博客 315

十部值得一看的电影

 十部值得一看的电影 【文件名称】----男人应该看的十部电影.torrent【文件大小】----6.47G【文件描述】1.罗马假日【爱情】 ◆原 名:Roman Holiday ◆译 名:罗马假日/罗马假期/金枝玉叶 ◆导  演:威廉 惠勒 (William Wyler) ◆演 员:格里高利 派克 (Gregory Peck) 奥黛丽 赫本 (Audr

天下文章一大抄,只有做得好,没有抄的好! 249万+

浏览网页出现乱码

     大家可能遇到这种情况,浏览一个网页会出现乱码,也就是除了图片以外会出现乱码。出现乱码的原因。 .      浏览器不支持网页的编码。这种情况比较常见。比如IE6的浏览器于遨游浏览同一网页,会出现显示不完整、乱码。当然同一浏览器的不同版本也有类似情况。IE6与IE8浏览器有些网页也会出现乱码、显示不全。       先分享一个我看过的网页内容。   

tiantian6036的专栏 67万+

hdu5527】【2015ACM/ICPC亚洲区长春站Too Rich

2015ACM/ICPC亚洲区长春站

曾经追梦的happy时光 1567

2015ACM/ICPC亚洲区长春站 A hdu 5527 Too Rich

Too Rich Time Limit: 6000/3000 MS (Java/Others)Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 245Accepted Submission(s): 76 Problem Description You are a rich person, ...

anmob303090的博客 279

Too Rich HDU - 5527 (思维题+贪心)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5527 Too Rich Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 1253    Accepted Submissi

Vision 666

HDU 5527 Too Rich (好题 贪心 DFS)

HDU 5527 Too Rich (贪心 DFS)

Tc的专栏 2494

hdu5527Too Rich

Too Rich Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 401    Accepted Submission(s): 119 Problem Description You are a rich pe

LJQ 954

HDU5527Too Rich(DFS & 贪心 & 思维)

Too Rich Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 1613    Accepted Submission(s): 413 Problem Description You are a rich p

junior19的博客 744

Too Rich HDU - 5527贪心+dfs)

Too Rich Time Limit: 6000/3000 MS (Java/Others)Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 1850Accepted Submission(s): 480 Problem Description You are a rich person, and...

weixin_30401605的博客 119

HDU5527 2015长春赛区A】【贪心 特判模拟】Too Rich 最多硬币数支付 因子思想 贪心打补丁

#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; void fre(){freopen("c://test//input.in","r",stdin);freopen("c:

snowy_smile的博客 1930

HDU 5527 Too Rich2015长春站A题&&贪心

比赛的时候最后35分钟队友写的,感觉最后可能太紧张了,写完了,但是没调完,然后这道题都没提交。。。分析:贪心,用尽量多的小面值的纸币来凑数,基本上每一个数都能整除后面一个数,所以前ii种面值最多能凑出sum[i]sum[i]圆,那么第i+1i+1种面值需要⌈p−sum[i]num[i+1]⌉\lceil{{p-sum[i]}\over{num[i+1]}}\rceil,此时有个小问题就是,2020并

无限大な梦のあとの 何もない世の中じゃ 778

ICPC 2015 Changchun A Too Rich贪心

问题 A: Too Rich 时间限制:1 Sec内存限制:128 MB 题目描述 You are a rich person, and you think your wallet is too heavy and full now. So you want to give me some money by buying a lovely pusheen sticker whic...

weixin_33859844的博客 143

Too Rich ICPC 2015 Changchun A dfs+思维

9255: Too Rich 时间限制:1 Sec内存限制:128 MB 提交:100解决:22 [提交] [状态] [讨论版] [命题人:admin] 题目描述 You are a rich person, and you think your wallet is too heavy and full now. So you want to give me some mon...

喵喵喵 286

hdu 5527 Too Rich

Too Rich Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 150    Accepted Submission(s): 25 Problem Description You are a rich per

bigwatermlon的博客 978

HDU 5527 贪心

Too Rich Time Limit: 6000/3000 MS (Java/Others)Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 1666Accepted Submission(s): 422 Problem Description You are a rich person, and...

weixin_33800593的博客 212
上一篇: [HDU 5521] 2015ACM/ICPC亚洲区沈阳站 Meeting 最短路
下一篇: [hdu 5532] [2015ACM/ICPC亚洲区长春站 ] Almost Sorted Array 最长不下降子序列
ALPS233
博客等级 码龄11年 25粉丝 191原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值