hdu2546饭卡-01背包
来源:互联网 发布:万网域名怎么转出 编辑:程序博客网 时间:2024/04/20 16:58
当卡上的金额大于等于5时,可以用5元去买任意价格的菜,所以当然是用这5元去买最贵的菜了,剩下的问题就是,求剩下的m-5元能买到的最高的价值总量。
#include <iostream>#include <algorithm>#include <cstring>#include <cstdio>using namespace std;int main(){ int n,m,i,j; int food[1002],dp[1002]; while(cin>>n&&n) { for(int i=0;i<n;i++) scanf("%d",&food[i]); cin>>m; if(m<5) { cout<<m<<endl; continue; } else { sort(food,food+n); memset(dp,0,sizeof(dp)); for(i=0;i<n-1;i++) for(int v=m-5;v>=food[i];v--) { dp[v]=max(dp[v],dp[v-food[i]]+food[i]); } cout<<m-dp[m-5]-food[n-1]<<endl; } } return 0;}
- HDU2546:饭卡(01背包)
- hdu2546 饭卡 (01背包)
- hdu2546饭卡-01背包
- hdu2546饭卡 (01背包)
- HDU2546:饭卡(01背包)
- HDU2546 饭卡 01背包
- HDU2546 饭卡(01背包)
- 【HDU2546】饭卡(01背包)
- 【01背包】HDU2546饭卡
- hdu2546饭卡(01背包)
- hdu2546 饭卡(01背包)
- Hdu2546-饭卡-【01背包】
- 01背包 hdu2546饭卡
- hdu2546 饭卡(01背包)
- hdu2546 饭卡 01-背包问题
- hdu2546饭卡(01背包)
- hdu2546 饭卡 (01背包)
- hdu2546饭卡(01背包)
- hdu 题目1298 T9(字典树)
- STL概述
- hdu 2594 Simpsons’ Hidden Talents
- HTML元素定位
- [2] Android进程孵化图
- hdu2546饭卡-01背包
- Oracle Shared pool 详解
- 用MapReduce 模拟日志发送,在Storm的Spout中接收UDP数据
- oracle体系结构
- 磁盘管理——RAID 1
- 【读书笔记】高效程序员的45个习惯
- 跳槽有关
- 映射集合属性之③:Set集合属性
- JVM监控以及常见的内存异常原因