HDU 2546 饭卡(01背包小变形)
2012-07-10 08:24
549 查看
题目链接:Click here~~
题意:
中文题不解释。
解题思路:
由于最后5元钱可以买任何价值的物品,所以为了使余额最少,我们应该用这5元钱买最贵的物品。
于是问题转化成了容量为V-5,除去一个最贵物品的01背包问题。
题意:
中文题不解释。
解题思路:
由于最后5元钱可以买任何价值的物品,所以为了使余额最少,我们应该用这5元钱买最贵的物品。
于是问题转化成了容量为V-5,除去一个最贵物品的01背包问题。
#include <stdio.h> #include <string.h> #define N 1005 #define max(a,b) a > b ? a : b int V,dp ; void Bag_01(int c,int w) { for(int i=V-5;i>=c;i--) dp[i] = max(dp[i],dp[i-c]+w); } int main() { int n,w ,mmax,loc; while(scanf("%d",&n),n) { mmax = loc = 0; memset(dp,0,sizeof(dp)); for(int i=1;i<=n;i++) { scanf("%d",&w[i]); if(mmax < w[i]) mmax = w[i] , loc = i; } w[loc] = w , w = mmax; scanf("%d",&V); if(V < 5) printf("%d\n",V); else { for(int i=1;i<=n-1;i++) Bag_01(w[i],w[i]); printf("%d\n",V-dp[V-5]-w ); } } return 0; }
相关文章推荐
- HDU 2546 饭卡(带限制的01背包变形)
- 饭卡 HDU-2546 【01背包变形】
- hdu 2546 饭卡【01背包变形||记忆化搜索】
- HDU 2546--饭卡【01背包变形】
- hdu 2546 饭卡(01背包变形)
- HDU 2546 饭卡(01 背包)
- 简单DP 01 背包 饭卡HDU 2546 ( 饭卡 ) 不知道算不算是稍稍加了点贪心的思想~
- HDU 2546 饭卡 基本的01背包
- HDU 2546 饭卡(01背包裸题)
- HDU 2546 —— 饭卡 01背包入门
- HDU 2546:饭卡(动态规划:01背包)
- HDU 2546 饭卡 (01背包--经典题型!)
- 饭卡 (背包01 一维数组) http://acm.hdu.edu.cn/showproblem.php?pid=2546
- hdu 2546 饭卡 01背包
- hdu2546 饭卡 (01 背包)
- hdu 2546 饭卡 01背包
- HDU - 2546 饭卡 —— 01背包
- HDU 2546 饭卡(01 背包)
- HDU 2546 饭卡 【入门DP之01背包问题】
- hdu 2546 饭卡 01背包