Euro Efficiency_完全背包
Description
A student buying a 68 guilder book before January 1st could pay for the book with one 50 guilder banknote and two 10 guilder banknotes, receiving two guilders in change. In short:50+10+10-1-1=68. Other ways of paying were: 50+25-5-1-1, or 100-25-5-1-1.Either way, there are always 5 units (banknotes or coins) involved in the payment process, and it
could not be done with less than 5 units.
Buying a 68 Euro book is easier these days: 50+20-2 = 68, so only 3 units are involved.This is no coincidence; in many other cases paying with euros is more efficient than paying with guilders. On average the Euro is more efficient. This has nothing to do, of course, with the value of the Euro, but with the units chosen. The units for guilders used to be: 1, 2.5, 5, 10, 25, 50,whereas the units for the Euro are: 1, 2, 5, 10, 20, 50.
For this problem we restrict ourselves to amounts up to 100 cents. The Euro has coins with values 1, 2, 5, 10, 20, 50 eurocents. In paying an arbitrary amount in the range [1, 100] eurocents, on average 2.96 coins are involved, either as payment or as change. The Euro series is not optimal in this sense. With coins 1, 24, 34, 39, 46, 50 an amount of 68 cents can be paid using two coins.The average number of coins involved in paying an amount in the range [1, 100] is 2.52.
Calculations with the latter series are more complex, however. That is, mental calculations.These calculations could easily be programmed in any mobile phone, which nearly everybody carries around nowadays. Preparing for the future, a committee of the European Central Bank is studying the efficiency of series of coins, to find the most efficient series for amounts up to 100 eurocents. They need your help.
Write a program that, given a series of coins, calculates the average and maximum number of coins needed to pay any amount up to and including 100 cents. You may assume that both parties involved have sufficient numbers of any coin at their disposal.
Input
Output
Sample Input
3
1 2 5 10 20 50
1 24 34 39 46 50
1 2 3 7 19 72
Sample Output
2.96 5
2.52 3
2.80 4
【题意】给出6个面值的钱,求拼出1-100的平均使用的数量和使用最多的数量
【思路】由于可以采取减法,我们采用两个两次循环,取最小值,一个从小到大,一个从大到小,完全背包
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
const int inf=;
const int N=;
int val[];
int dp[N+];
int main()
{ int t;
scanf("%d",&t);
while(t--)
{
for(int i=;i<=;i++)
{
scanf("%d",&val[i]);
} dp[]=;
for(int i=;i<=N;i++)
dp[i]=inf;//开始用memset答案不行
for(int i=;i<=;i++)
{
for(int j=val[i];j<=N;j++)
{
dp[j]=min(dp[j],dp[j-val[i]]+);
}
}
for(int i=;i<=;i++)
{
for(int j=N-val[i];j>=;j--)
{
dp[j]=min(dp[j],dp[j+val[i]]+);
}
}
int sum=;int maxn=;
for(int i=;i<=;i++)
{
sum+=dp[i];
maxn=max(maxn,dp[i]);
}
double ans=(double)sum/;
printf("%.2f %d\n",ans,maxn); }
return ;
}
Euro Efficiency_完全背包的更多相关文章
- Euro Efficiency(完全背包)
Euro Efficiency Time Limit : 2000/1000ms (Java/Other) Memory Limit : 20000/10000K (Java/Other) Tot ...
- POJ 1252 Euro Efficiency(完全背包, 找零问题, 二次DP)
Description On January 1st 2002, The Netherlands, and several other European countries abandoned the ...
- POJ 1252 Euro Efficiency ( 完全背包变形 && 物品重量为负 )
题意 : 给出 6 枚硬币的面值,然后要求求出对于 1~100 要用所给硬币凑出这 100 个面值且要求所用的硬币数都是最少的,问你最后使用硬币的平均个数以及对于单个面值所用硬币的最大数. 分析 : ...
- POJ 1252 Euro Efficiency(最短路 完全背包)
题意: 给定6个硬币的币值, 问组成1~100这些数最少要几个硬币, 比如给定1 2 5 10 20 50, 组成40 可以是 20 + 20, 也可以是 50 -10, 最少硬币是2个. 分析: 这 ...
- Poj 1276 Cash Machine 多重背包
Cash Machine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 26172 Accepted: 9238 Des ...
- poj 1276 Cash Machine(多重背包)
Cash Machine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 33444 Accepted: 12106 De ...
- POJ1276Cash Machine[多重背包可行性]
Cash Machine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 32971 Accepted: 11950 De ...
- Cash Machine_多重背包
Description A Bank plans to install a machine for cash withdrawal. The machine is able to deliver ap ...
- POJ1276:Cash Machine(多重背包)
Description A Bank plans to install a machine for cash withdrawal. The machine is able to deliver ap ...
随机推荐
- Java集合——Set接口
1.定义 set中不允许放入重复的元素(元素相同时只取一个),使用equals()方法进行比较.如果返回true,两个对象的HashCode值也应该相等 2.方法 add():添加元素 remove( ...
- Jquery 表格操作,记录分页情况下,每一页中被用户勾选的信息
如下图,一个分页列表,用户可以随意勾选一条或多条信息,然后进行某种操作,如“提交”.但是有个问题:如果勾选了一条信息之后,点[下一页],那么上一页 勾选的条目被刷新掉了. 问题:如果用户需要在第1页, ...
- 使用openssl库实现RSA、AES数据加密
openssl是可以很方便加密解密的库,可以使用它来对需要在网络中传输的数据加密.可以使用非对称加密:公钥加密,私钥解密.openssl提供了对RSA的支持,但RSA存在计算效率低的问题,所 ...
- Git 提交大文件提示 fatal: The remote end hung up unexpectedly
使用gitlab搭建的git server,如果直接使用http的方式去提交的话,提交小文件不会有问题,但是提交大文件时,会出错: fatal: The remote end hung up unex ...
- ASP.NET-【状态管理】-Cookie小结
Cookie路径 谷歌浏览器 依次点击设置--高级选项--内容设置--cookies--选择“显示cookies和其他网站数据”按钮就可以看到了 C:\Users\Administrator\Loca ...
- Servlet+JSP+JavaBean开发模式(MVC)介绍
好伤心...写登陆注册之前看见一篇很好的博文,没有收藏,然后找不到了. 前几天在知乎上看见一个问题,什么时候感觉最无力. 前两天一直想回答:尝试过google到的所有solve case,结果bug依 ...
- ssh localhost “Permission denied (publickey)
再次遇到 SSH Server And "Permission denied (publickey) 用这个关键词搜索才找到howtogeek上答案: sshd : Authenticati ...
- 使用System.Timers.Timer类实现程序定时执行
使用System.Timers.Timer类实现程序定时执行 在C#里关于定时器类有3个:System.Windows.Forms.Timer类.System.Threading.Timer类和Sys ...
- [Js]缓冲运动
一.运动框架 1.在开始运动时,关闭已有定时器(否则会不断有新的定时器执行) 2.把运动和停止隔开(if/else) 二.缓冲运动 逐渐变慢,最后停止(距离越远速度越大) 速度=(目标值-当前值)/缩 ...
- ASP.NET MVC 基于角色的权限控制系统的示例教程
上一次在 .NET MVC 用户权限管理示例教程中讲解了ASP.NET MVC 通过AuthorizeAttribute类的OnAuthorization方法讲解了粗粒度控制权限的方法,接下来讲解基于 ...