POJ 3628 Bookshelf 2【01背包】
题意:给出n头牛的身高,以及一个书架的高度,问怎样选取牛,使得它们的高的和超过书架的高度最小。
将背包容量转化为所有牛的身高之和,就可以用01背包来做===
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 2000005
using namespace std;
int dp[maxn],h[];
int main()
{
int n,b,i,j,sum=,tmp=;
scanf("%d %d",&n,&b);
for(i=;i<=n;i++)
{
scanf("%d",&h[i]);
sum+=h[i];
}
for(i=;i<=n;i++)
{
for(j=sum;j>=h[i];j--)
{
dp[j]=max(dp[j],dp[j-h[i]]+h[i]);
{
if(dp[j]>=b&&j<tmp)
tmp=j;
}
}
}
printf("%d\n",tmp-b);
}
POJ 3628 Bookshelf 2【01背包】的更多相关文章
- POJ 3628 Bookshelf 2 0-1背包
传送门:http://poj.org/problem?id=3628 题目看了老半天,牛来叠罗汉- -|||和书架什么关系啊.. 大意是:一群牛来叠罗汉,求超过书架的最小高度. 0-1背包的问题,对于 ...
- POJ 3628 Bookshelf 2 (01背包)
Bookshelf 2 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7496 Accepted: 3451 Descr ...
- POJ 3628 Bookshelf2(0-1背包)
http://poj.org/problem?id=3628 题意:给出一个高度H和n个牛的高度,要求把牛堆叠起来达到H,求出该高度和H的最小差. 思路:首先我们计算出牛的总高度sum,sum-H就相 ...
- POJ 3628 Bookshelf 2【背包型DFS/选or不选】
Bookshelf 2 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11105 Accepted: 4928 Desc ...
- POJ 3211 Washing Clothes(01背包)
POJ 3211 Washing Clothes(01背包) http://poj.org/problem?id=3211 题意: 有m (1~10)种不同颜色的衣服总共n (1~100)件.Dear ...
- poj 3628 Bookshelf 2
http://poj.org/problem?id=3628 01背包 #include <cstdio> #include <iostream> #include <c ...
- POJ3628 Bookshelf 2(01背包+dfs)
Bookshelf 2 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8745 Accepted: 3974 Descr ...
- [POJ 2184]--Cow Exhibition(0-1背包变形)
题目链接:http://poj.org/problem?id=2184 Cow Exhibition Time Limit: 1000MS Memory Limit: 65536K Total S ...
- POJ 3624 Charm Bracelet(01背包裸题)
Charm Bracelet Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 38909 Accepted: 16862 ...
随机推荐
- C#与C++之间类型的对应{转}
Windows Data Type .NET Data Type BOOL, BOOLEAN Boolean or Int32 BSTR String BYTE Byte CHAR ...
- SWF Web播放器
<HTML> <HEAD> <!-- saved from url=(0013)about:internet --> <TITLE> Untitled. ...
- cf div2 238 D
D. Toy Sum time limit per test 1 second memory limit per test 256 megabytes input standard input out ...
- NetCore第一步:千里之行 始于环境构筑
今年的6月28号,微软发布了一个正式版本 NetCore.发布的同时,也同时发布了CoreStudio. 这个激动人心的时刻,让跨平台已经不再是什么神话. 让我们一起来开始Core的开发之旅吧. 万事 ...
- MySQL: InnoDB 还是 MyISAM? (转载)
MyISAM存储引擎 原文作者:http://www.cnblogs.com/villion/archive/2009/07/09/1893762.html MyISAM是 默认存储引擎.它基于更老的 ...
- iOS开发之都兴忱小结
1.NSArray/NSDictionary ------> strong temp和self.arr是同一地址. 2.NSArray/NSDictionary ------->copy ...
- weka平台下手动造.arff的数据
若数据为 sunny,hot,high,FALSE,nosunny,hot,high,TRUE,noovercast,hot,high,FALSE,yesrainy,mild,high,FALSE,y ...
- hdu 4762 Cut the Cake (大数乘法)
猜公式: ans=n/m^(n-1) #include<stdio.h> #include<string.h> struct BigNum { ]; int len; }; i ...
- awk除去重复行
awk去除重复行,思路是以每一行的$0为key,创建一个hash数组,后续碰到的行,如果数组里已经有了,就不再print了,否则将其print 测试文件: 用awk: 用sort+uniq好像出错了: ...
- 304. Range Sum Query 2D - Immutable
题目: Given a 2D matrix matrix, find the sum of the elements inside the rectangle defined by its upper ...