HDU2546 (01背包)
来源:互联网 发布:锐捷网络和华为 编辑:程序博客网 时间:2024/05/17 02:06
01背包题
注意留出五块钱减去最贵的商品即可
#include "iostream"#include <stdio.h>#include <algorithm>#include <queue>#include "string.h"#include "math.h"using namespace std;int cmp(int a,int b){ return a<b;}int main(){ int n,money; int dp[1005]; int ss[1005]; while(scanf("%d",&n)&&n) { memset(dp,0,sizeof dp); for(int i=1;i<=n;i++) scanf("%d",&ss[i]); scanf("%d",&money); if(money<5) {printf("%d\n",money);continue;} sort(ss+1,ss+n+1,cmp); for(int i=1;i<=n-1;i++) for(int j=money-5;j>=ss[i];j--) dp[j]=max(dp[j],dp[j-ss[i]]+ss[i]); printf("%d\n",money-ss[n]-dp[money-5]); } return 0;}
0 0
- HDU2546 (01背包)
- HDU2546(01背包)
- hdu2546 饭卡(01背包)
- hdu2546饭卡(01背包)
- hdu2546 饭卡 (01背包)
- hdu2546饭卡(01背包)
- HDU2546 饭卡(01背包)
- HDU2546--饭卡(01背包)
- hdu2546(01背包变形)
- HDU2546 饭卡(01背包)
- HDU2546~饭卡(01背包)
- hdu2546 饭卡 (dp 01背包)
- hdu2546饭卡(动规 01背包)
- hdu2546 — 饭卡 (01背包)
- hdu2546 饭卡(01背包水)
- hdu2546 饭卡(01背包 dp)
- hdu2546饭卡(经典01背包题目)
- HDU2546 01背包
- 黑马程序员------正则表达式
- IP协议 Header Checksum算法
- js 原型继承
- MonoDevelop代码提示前有个P、C、E。这些标志都代表什么?
- ——黑马程序员——OC中的基本概念
- HDU2546 (01背包)
- sipXecs技术交流QQ群
- ForeResult.java
- 二维码操作第三方库
- PHP编译configure时常见错误
- 用sscanf()从字符串中读数
- asp.net 时间戳与datetime 转换
- RemoveEnd.java
- linux下 安装php的gettext模块