hdu2546 01背包
来源:互联网 发布:美股炒股软件 编辑:程序博客网 时间:2024/05/01 11:57
如题:http://acm.hdu.edu.cn/showproblem.php?pid=2546
当饭卡里的钱数不足5元 什么都不能买,直接输出钱数
否则
升序排序,max是最之前的菜的钱数
钱数先减去5,然后01背包在(1.。。n-1)个菜中计算最高花费,最后输出m+5-f[m]-max
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MN 1002
#define MV 1002
#define max(a,b)(a>b?a:b)
int c[MN];
int f[MV];
int n,m;
int cmp(const void * a,const void * b)
{
return (*(int *)a)-(*(int *)b);
}
int main()
{
while(scanf("%d",&n)&&n)
{
memset(f,0,sizeof(f));
int i,j;
for(i=1;i<=n;i++)
scanf("%d",&c[i]);
scanf("%d",&m);
qsort(c+1,n,sizeof(int),cmp);
if(m<5)
{
printf("%d\n",m);
continue;
}
m-=5;
int max=c[n];
for(i=1;i<n;i++)
for(j=m;j>=c[i];j--)
f[j]=max(f[j],f[j-c[i]]+c[i]);
printf("%d\n",m+5-f[m]-max);
}
}
- HDU2546 01背包
- HDU2546:饭卡(01背包)
- hdu2546 饭卡 (01背包)
- hdu2546饭卡-01背包
- hdu2546饭卡 (01背包)
- HDU2546:饭卡(01背包)
- HDU2546 饭卡 01背包
- hdu2546 01背包
- HDU2546 (01背包)
- HDU2546 饭卡(01背包)
- HDU2546 01背包
- 【HDU2546】饭卡(01背包)
- 【01背包】HDU2546饭卡
- HDU2546(01背包)
- hdu2546饭卡(01背包)
- hdu2546-01背包
- hdu2546 饭卡(01背包)
- 01背包 hdu2546 hdu2602
- Wamp配置虚拟主机目录
- 在淘宝知识产权保护平台发起投诉,应该如何撰写投诉理由?
- POJ 题目1850 Code(组合数学)
- 阿里小号平台“淘乐高”淘宝知识免费讲座火热报名中
- 二进制、八进制、十进制、十六进制之间转换
- hdu2546 01背包
- Android 通知栏Notification的整合 全面学习 (一个DEMO让你完全了解它)
- getchar和putchar
- [笔记]WEB开发之3456:Html5标签
- linux 安装jdk
- 通透红黑树
- java 中abstract class和interface有什么区别
- 删除重复记录
- IOS1.5-图片浏览(示例)