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 ...
 
随机推荐
- UserAgent:通过浏览器获取用户浏览器等信息
			
User Agent的含义 User Agent中文名为用户代理,简称 UA,它是一个特殊字符串头,使得服务器能够识别客户使用的操作系统及版本.CPU 类型.浏览器及版本.浏览器渲染引擎.浏 ...
 - TortoiseGit GitHub 使用指南
			
TortoiseGit GitHub 使用指南 这个文档讲的还是比较清楚和完整的.需要注意的一点是ssh的方式,取gitHub的URL的时候选取ssh方式. http://www.360doc.co ...
 - backbonejs mvc框架的增删查改实例
			
一:开发环境 coffeescript和nodejs需要先安装,没装网上自己查安装步骤. 代码编写环境及esp框架下载: esp框架下载地址:https://github.com/nonocast/e ...
 - IE10 CSS hack,IE兼容问题
			
IE10 CSS hack,IE兼容问题 作者: 雪影 发表于2013 年 4 月 25 日 分类:技术分享 | 暂无评论 | 人气: 376 度 首先,ie10不支持条件注释了. 方法一:特性检测: ...
 - poi 读取 excel (.xls) 97-2003
			
1.sh.getLastRowNum() 比行数少1 private List<Map> getData(File file) throws Exception{ List<Map& ...
 - Objective-C(一简介)
			
Objective-C简介 通常写作ObjC和较少用的Objective C或Obj-C,是扩充C的面向对象编程语言.它主要使用于Mac OS X和GNUstep这两个使用OpenStep标准的系统, ...
 - DataGridView批量执行Insert和Remove行时特别慢的解决方案
			
向DataGridView循环插入110条数据耗时5秒多. 在循环前执行: var oldAutoSizeRowsMode = this.AutoSizeRowsMode; var oldAutoSi ...
 - [Js]滑动门效果
			
描述:鼠标移动到一副图片上,会显示该副图片的全貌,而其他图片会显示概貌 一.没有动画效果的运动 思路: 1.定好每张图片的初始位置(第一张完全显示,234只露出一部分) 2.计算每道门的移动距离(即未 ...
 - POJ 3299 Humidex 难度:0
			
题目链接:http://poj.org/problem?id=3299 #include <iostream> #include <iomanip> using namespa ...
 - caches 文件夹删除
			
模拟器 可以 删除 真机不行