poj 1252 Euro Efficiency 完全背包,可以找零

来源:互联网 发布:软件杯 编辑:程序博客网 时间:2024/05/14 03:30

题目大意:给6种不同面额硬币,求组成[1,100]中数的平均需要硬币与最多需要硬币数,可以通过减法获得,比如有1、4两种硬币,凑成3可以用4-1两个硬币完成,而不是1+1+1三个硬币。


乍一看,很水的题,DP做得话要注意两点:

一:题目不仅仅有+的操作,也有哦-的操作,所以需要正向和反向各dp一遍才行。。

二:题目dp不能只开到100.。而是要开大点,到2000足以。。因为我们假设。。存在1、95、96、97、98、99这样又大又互质的数据。。那么算的话会算到很大的数,所以需要多开。。2000就够。。网上大牛说的。。。

Description

On January 1st 2002, The Netherlands, and several other European countries abandoned their national currency in favour of the Euro. This changed the ease of paying, and not just internationally. 
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

The first line of the input contains the number of test cases. Each test case is described by 6 different positive integers on a single line: the values of the coins, in ascending order. The first number is always 1. The last number is less than 100. 

Output

For each test case the output is a single line containing first the average and then the maximum number of coins involved in paying an amount in the range [1, 100]. These values are separated by a space. As in the example, the average should always contain two digits behind the decimal point. The maximum is always an integer. 

Sample Input

31 2 5 10 20 501 24 34 39 46 501 2 3 7 19 72

Sample Output

2.96 52.52 32.80 4

题目其实真心不难,但是交上去总是WA,最后搞不懂了,只好看看别人的才知道上界弄错了。。。。

#include<cstdio>#include<iostream>#include<algorithm>#include<cstring>using namespace std;#define INF 0x3f3f3f3fint dp[20001],w[2001];int main(){    int t;    scanf("%d",&t);    while(t--)    {        for(int i=0; i<6; i++)            scanf("%d",&w[i]);        for(int i=1; i<=2000; i++)            dp[i]=INF;        dp[0]=0;        for(int i=0; i<6; i++)            for(int j=w[i]; j<=2000; j++)          //这个地方犯二了,竟然只开到100后来错了好几次实在找不到哪错了看了别人的代码才发现不能只开到100                dp[j]=min(dp[j],dp[j-w[i]]+1);        for(int i=0; i<6; i++)            for(int j=2000-w[i]; j>=1; j--)                dp[j]=min(dp[j],dp[j+w[i]]+1);        int maxl=0;        double sum=0;        for(int i=1; i<=100; i++)        {            if(maxl<dp[i])            {                maxl=dp[i];            }            //printf("i=%d dp==%d\n",i,dp[i]);            sum+=dp[i];        }       // printf("***%d\n",sum);        printf("%.2f %d\n",sum/100,maxl);    }    return 0;}


0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 玩lol显示器超频怎么办 win10显示器超频黑屏怎么办 电脑开机显示超频怎么办 玩英雄联盟网卡怎么办 英雄联盟超屏怎么办 三星手机基带未知怎么办 显卡进桌面黑屏怎么办 电脑开机黑屏怎么办打开 ap黑屏打不开了怎么办 老人机屏幕变黑怎么办 电脑一直弹网页怎么办 电脑一直跳网页怎么办 电脑网页一直转圈怎么办 消费者联盟闪退怎么办 门卡住了打不开怎么办 悦平台出现bug怎么办 lol开不了全屏怎么办 韩服lol忘记密码怎么办 股票交易密码忘记了怎么办 指纹解锁密码忘记怎么办 玩lol美服有延迟怎么办 逆水寒黑屏崩溃怎么办 逆水寒游戏崩溃怎么办 lol切换黑屏了怎么办 英雄联盟花屏怎么办 笔记本开机黑屏怎么办 win10 笔记本联盟fps低怎么办 lol超出显示范围怎么办 lol游戏进去黑屏怎么办 lol老是卡顿怎么办 lol无响应怎么办黑屏 电脑进游戏慢怎么办 电脑登录游戏慢怎么办 手机连不上手柄蓝牙怎么办? steam游戏出现bug怎么办 电脑蓝屏后黑屏怎么办 iphonex屏幕跳屏怎么办 玩lol网络卡怎么办 逆战活动点不开怎么办 dnf内活动打不开怎么办 玩第五人格网卡怎么办