http://acm.hdu.edu.cn/showproblem.php?pid=2546

经典的01背包

预留5元买最贵的,剩余的就是01背包。

#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
int main()
{
int pr[],bao[],i,j,n,m,ma;
while(~scanf("%d",&n),n)
{
memset(bao,,sizeof(bao));
for(i=;i<=n;i++)
scanf("%d",&pr[i]);
sort(pr+,pr++n);
scanf("%d",&m);
if(m<)
{
printf("%d\n",m);
continue;
}
m-=;
for(i=;i<n;i++)
{
for(j=m;j>=pr[i];j--)
{
bao[j]=max(bao[j],bao[j-pr[i]]+pr[i]);
}
}
printf("%d\n",m+-bao[m]-pr[n]);
}
return ;
}

HDU 2546 01背包的更多相关文章

  1. HDU 2546(01背包)

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

  2. hdu 2546 0-1背包

    #include<stdio.h> #include<string.h> #define N 1100 int dp[N],a[N]; int main() { int n,m ...

  3. hdu 1203 01背包 I need a offer

    hdu 1203  01背包  I need a offer 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1203 题目大意:给你每个学校得到offe ...

  4. hdu 1864 01背包 最大报销额

    http://acm.hdu.edu.cn/showproblem.php?pid=1864 New~ 欢迎“热爱编程”的高考少年——报考杭州电子科技大学计算机学院关于2015年杭电ACM暑期集训队的 ...

  5. hdu 2955 01背包

    http://acm.hdu.edu.cn/showproblem.php?pid=2955 如果认为:1-P是背包的容量,n是物品的个数,sum是所有物品的总价值,条件就是装入背包的物品的体积和不能 ...

  6. [HDOJ1171]Big Event in HDU(01背包)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1171 许多有价值的物品,有重复.问如何将他们分成两堆,使两堆价值之差最小. 对价值求和,转换成01背包 ...

  7. HDU 2639 01背包(分解)

    http://acm.hdu.edu.cn/showproblem.php?pid=2639 01背包第k优解,把每次的max分步列出来即可 #include<stdio.h> #incl ...

  8. HDU 1171 01背包

    http://acm.hdu.edu.cn/showproblem.php?pid=1171 基础的01背包,求出总值sum,背包体积即为sum/2 #include<stdio.h> # ...

  9. hdoj1171 Big Event in HDU(01背包 || 多重背包)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1171 题意 老师有一个属性:价值(value).在学院里的老师共有n种价值,每一种价值value对应着 ...

随机推荐

  1. props传递数据

    一.传递数据 1.props 传入单数据 就像 data 一样,prop 可以用在模板内,同样也可以在 vm 实例中像“this.message”这样使用 <template> <d ...

  2. Sublime Text3 常用快捷键必看

    Sublime Text3 常用快捷键必看  https://blog.csdn.net/md1688/article/details/53043525

  3. (转)无效的CurrentPageIndex 值。它必须大于等于0 且小于PageCount 解决方案

    第一种: 当以某种条件来查询的时候 其中的结果是以一个结果为条件的datagrid分页 采用字查询到条件下加入如下代码: [c-sharp] view plaincopyprint? protecte ...

  4. andorid 手机外部储存

    .xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android ...

  5. Android.StructureOfAndroidSourceCodeRootTree

    Refference 1. How to understand the directory structure of android root tree? http://stackoverflow.c ...

  6. CentOS6.2网卡绑定配置

    下面主要介绍在CentOS6.2下使用系统自带的bonding进行网卡绑定的详细步骤,在此之前你可以看一下Linux网卡绑定探析,你也可以使用网卡绑定的脚本进行网卡绑定操作. 注意:请在配置前关闭Ne ...

  7. Best Sightseeing Pair LT1014

    Given an array A of positive integers, A[i] represents the value of the i-th sightseeing spot, and t ...

  8. Previous Permutation

    Similar to next permutation, the steps as follow: 1) Find k in the increasing suffix such that nums[ ...

  9. h5页面适配iPhone X的方法

    一.原生适配iphoneX 原生适配很简单,查看机型图:   只要用 #define KIsiPhoneX ([UIScreen mainScreen].bounds.size.height>8 ...

  10. Java:斐波那契数列

    斐波那契数列指的是这样一个数列 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233,377,610,987,1597,2584,4181,6765,10 ...