poj 3628
来源:互联网 发布:用户日志 程序员日志 编辑:程序博客网 时间:2024/04/28 13:33
上午用背包做 没想出 然后直接暴搜 AC 下午 突然想出一个方法 果断AC
#include<stdio.h>
#include<string.h>
#define Max 20000010
int dp[Max];
int N,B;
int weight[30];
int max(int a,int b)
{
return a>b?a:b;
}
int main()
{
int tem;
int min;
int sum=0;
int MAX;
while(scanf("%d%d",&N,&B)!=EOF)
{
min=Max;
MAX=sum=0;
for(int i=0; i<N; i++)
{
scanf("%d",&tem);
MAX+=tem;
if(tem>B)
{
if(min>tem-B)
min=tem-B;
continue;
}
weight[sum++]=tem;
}
for(int k=0;k<=MAX;k++)
dp[k]=0;
for(int k=0; k<sum; k++)
for(int j=MAX; j>=weight[k]; j--)
{
dp[j]=max(dp[j],dp[j-weight[k]]+weight[k]);
if(dp[j]>=B)
{
if(min>dp[j]-B)
min=dp[j]-B;
}
}
printf("%d\n",min);
}
return 0;
}
- poj 3628
- POJ 3628
- poj-3628
- poj 3628
- poj 3628
- POJ 3628 - Bookshelf 2
- POJ 3628 - Bookshelf 2
- POJ 3628 Bookshelf 2
- poj-3628-Bookshelf 2
- poj 3628 01背包
- poj 3628 01背包
- poj 3628 01 背包
- poj 3628 Bookshelf 2
- POJ 3628 Bookshelf 2
- POJ 3628 Bookshelf 2
- poj 3628 Bookshelf 2
- POJ 3628-Bookshelf 2
- POJ - 3628 Bookshelf 2
- iOS App通过itunes共享文件
- 如何在java程序中使用sikuli脚本
- Ext.grid.GridPanel .
- cocos2d-x 遮罩效果实现
- 最短路径算法研究未完成的算法
- poj 3628
- [django]在模板上自定义显示内容(django tag)
- HTTP协议详解(真的很经典)
- Ajax初学者(2)
- [IDE]eclipse各种插件的下载地址
- 资源,类对象
- 资金管理要领和交易策略举要
- /dev/mem
- 操作分区表对global和local索引的影响 (转)