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 ...
随机推荐
- AppSettings和ConnectionStrings的区别
AppSettings是ASP.NET1.1时期用的,在.NET Framework 2.0中,新增了ConnectionStrings. 1.<connectionStrings> &l ...
- splunk 索引过程
术语: Event :Events are records of activity in log files, stored in Splunk indexes. 简单说,处理的日志或话单中中一行记录 ...
- 斐波那契博弈(Fibonacci Nim)
问题: 有一堆个数为n(n>=2)的石子,游戏双方轮流取石子,规则如下: 1)先手不能在第一次把所有的石子取完,至少取1颗: 2)之后每次可以取的石子数至少为1,至多为对手刚取的石子数的2倍. ...
- (转)虚拟机的桥接模式和NAT模式区别
不管是虚拟机的桥接还是NAT都是占用实机网络的.只不过两种方式有些差异,在通过IP或者拨号连接限速的网络中,差异就很明显了 举个不太恰当但简单的例子,一个百兆的网卡你可以把它想象成一个100车 ...
- mysql连接数据库p的大小写
命令:mysql -uroot -p -hlocalhost -P3306 -h 用来指定远程主机的IP -P (大写) 用来指定远程主机MYAQL的绑定端口
- spring mvc表单自动装入实体对象
<form action="/springmvc1/user/add" method="post"> id: <input type=&quo ...
- HookIAT的启动程序
// 启动程序.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <Windows.h> #include &l ...
- SQL CAST, CONVERT 比较
本文转自:http://www.cnblogs.com/denylau/archive/2010/12/01/1893371.html if (@StartTime > @EndTime) ...
- C语言基础--switch
switch格式: switch (条件表达式) { case 整数: // case可以有一个或多个 语句; break; case 整数: 语句; break; default: 语句; brea ...
- CCNA 6.5
no sh (no shutdown : start the interface) router rspf 1 network x.x.x.x x.x.x.x area 0 int (interf ...