用5块钱去买最贵的物品,用剩下的m-5块去买尽量多的物品

 #include<stdio.h>
#include<math.h>
#include<vector>
#include<stdlib.h>
#include<string.h>
#include<iterator>
#include<iostream>
#include<algorithm>
#include<set>
#include<map>
using namespace std; int dp[],cost[]; int main()
{
int n,money,max_cost;
while(scanf("%d",&n) && n!=)
{
memset(cost,,sizeof(cost));
memset(dp,,sizeof(dp));
for(int i=;i<=n;i++)
scanf("%d",&cost[i]);
scanf("%d",&money); sort(cost+,cost+n+); max_cost=cost[n]; if(money<)
printf("%d\n",money); else
{
for(int i=;i<n;i++) //----------注意是n-1因为最大的n已经取走
for(int j=money-;j>=cost[i];j--)
dp[j]=max(dp[j],dp[j-cost[i]]+cost[i]); printf("%d\n",money-max_cost-dp[money-]);
}
}
return ;
}

hdu 2546饭卡的更多相关文章

  1. HDOJ(HDU).2546 饭卡(DP 01背包)

    HDOJ(HDU).2546 饭卡(DP 01背包) 题意分析 首先要对钱数小于5的时候特别处理,直接输出0.若钱数大于5,所有菜按价格排序,背包容量为钱数-5,对除去价格最贵的所有菜做01背包.因为 ...

  2. HDU 2546 饭卡(01背包)

    题目代号:HDU 2546 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2546 饭卡 Time Limit: 5000/1000 MS (Java/ ...

  3. HDU 2546 饭卡

    http://acm.hdu.edu.cn/showproblem.php?pid=2546 呆呆. 饭卡 Time Limit: 5000/1000 MS (Java/Others)    Memo ...

  4. HDU 2546 饭卡(01背包裸题)

    饭卡 Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submiss ...

  5. hdu 2546 饭卡(背包)

      设饭卡余额为total 此题经分析 可以得出:要求选出一些饭菜 时消费量尽量接近total-5元 然后再买一个饭菜 以达到透支... 可以证明 最后买的那个饭菜是饭菜中价值最大的. 证明 设a1 ...

  6. HDU 2546 饭卡(0-1背包)

    http://acm.hdu.edu.cn/showproblem.php?pid=2546 题意: 电子科大本部食堂的饭卡有一种很诡异的设计,即在购买之前判断余额.如果购买一个商品之前,卡上的剩余金 ...

  7. HDU 2546 饭卡(01 背包)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=2546 思路:需要首先处理一下的的01背包,当饭卡余额大于等于5时,是什么都能买的,所以题目要饭卡余额最小, ...

  8. hdu 2546 饭卡 删除一个数的01背包

    饭卡 Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submissi ...

  9. 【01背包】HDU 2546 饭卡

    Time Limit : 5000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Submission(s) ...

  10. hdu 2546 饭卡 (01背包)

    Problem Description 电子科大本部食堂的饭卡有一种很诡异的设计,即在购买之前判断余额.如果购买一个商品之前,卡上的剩余金额大于或等于5元,就一定可以购买成功(即使购买后卡上余额为负) ...

随机推荐

  1. html5 图片转为base64格式异步上传

    因为有这个需求(移动端),所以就研究了一下,发现还挺不错的.这个主要是用了html5的API,不需要其他的JS插件,不过只有支持html5的浏览器才行,就现在而言应该大部份都支持的.<!DOCT ...

  2. 剑指Offer 反转链表

    题目描述 输入一个链表,反转链表后,输出链表的所有元素.     思路: 法1:用栈,压栈出栈 法2:头插法(有递归非递归2中)   AC代码: /* struct ListNode { int va ...

  3. Caffe学习系列(9):solver优化方法

    介绍了各种优化算法 参考:http://www.cnblogs.com/denny402/p/5074212.html

  4. SVN权限管理

    转自:http://www.cnblogs.com/xingchen/archive/2010/07/22/1782684.html /******************************** ...

  5. iframe自适应宽度

    <iframe id="course_content" style="width:100%;margin:5px 0 0;" scrolling=&quo ...

  6. java servlet的工作原理

    servlet本质上就是java类嘛.不过是有特殊规范的java类而已.下面就说一说为什么servlet要有特殊规范. 首先,考虑一下什么地方用servlet,WEB应用,而且是需要servlet容器 ...

  7. 【leetcode】Substring with Concatenation of All Words

    Substring with Concatenation of All Words You are given a string, S, and a list of words, L, that ar ...

  8. 解决Django发送中文邮件时的编码及乱码问题

    参考自---http://blog.csdn.net/clh604/article/details/9274793 #-*- coding=utf8 -*- from email.message im ...

  9. iOS 目录的使用

    Table 1-1  Commonly used directories of an iOS app  Directory Description AppName.app This is the ap ...

  10. linux学习之lvm-逻辑卷管理器

    一.简介 lvm即逻辑卷管理器(logical volume manager),它是linux环境下对磁盘分区进行管理的一种机制.lvm是建立在硬盘和分区之上的一个逻辑层,来提高分区管理的灵活性.它是 ...