PKU--3628 Bookshelf 2(01背包)】的更多相关文章

传送门:http://poj.org/problem?id=3628 题目看了老半天,牛来叠罗汉- -|||和书架什么关系啊.. 大意是:一群牛来叠罗汉,求超过书架的最小高度. 0-1背包的问题,对于第i只牛可以放或者不放.然后最后求出大于书架高度的,减去书架高度即可. 也可以倒着来看.背包的容量为牛总的高度-书架的高度,求不超过这个容量的最大值,最后容量-这个值就是答案了.(推荐) 还可以DFS.. #include<cstdio> #include<cstring> #incl…
Bookshelf 2 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7496   Accepted: 3451 Description Farmer John recently bought another bookshelf for the cow library, but the shelf is getting filled up quite quickly, and now the only available…
Bookshelf 2 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8745   Accepted: 3974 Description Farmer John recently bought another bookshelf for the cow library, but the shelf is getting filled up quite quickly, and now the only available…
题意: 有一些牛,每头牛有一个Si值,一个Fi值,选出一些牛,使得max( sum(Si+Fi) ) 并且 sum(Si)>=0, sum(Fi)>=0 思路: 随便选一维做容量(比如Fi),另一维做价值,然后直接做01背包. 做的时候注意一下方向. 最后,在合法解里面找一下最优解就好了. 代码: #include <iostream> #include <cstdio> #include <cstring> #include <cstdlib>…
http://poj.org/problem?id=3628 题意:给出一个高度H和n个牛的高度,要求把牛堆叠起来达到H,求出该高度和H的最小差. 思路:首先我们计算出牛的总高度sum,sum-H就相当于一个背包容量,如果我们往里装高度正好等于了sum-H,也就是说明我们堆叠的牛的高度正好等于了H. 这样一来很好理解,就是计算在一个背包容量为sum-H的背包中最多能装多少.题目本身还是不难的,直接套用模板就行了. #include<iostream> #include<algorithm…
Bookshelf 2 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11105   Accepted: 4928 Description Farmer John recently bought another bookshelf for the cow library, but the shelf is getting filled up quite quickly, and now the only availabl…
B - Bookshelf 2 Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Submit Status Description Farmer John recently bought another bookshelf for the cow library, but the shelf is getting filled up quite quickly, and now the only…
题意:给出n头牛的身高,以及一个书架的高度,问怎样选取牛,使得它们的高的和超过书架的高度最小. 将背包容量转化为所有牛的身高之和,就可以用01背包来做=== #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define maxn 2000005 using namespace std; ]; int main() { ,tmp=; scanf("%…
Description Farmer John recently bought another bookshelf for the cow library, but the shelf is getting filled up quite quickly, and now the only available space is at the top. FJ has N cows (1 ≤ N ≤ 20) each with some height of Hi (1 ≤ Hi ≤ 1,000,00…
题目链接:Bookshelf 2(点击进入) 题目解读: 给n头牛,给出每个牛的高度h[i],给出一个书架的高度b(所有牛的高度相加>书架高度b),现在把一些牛叠起来(每头牛只能用一次,但不同的牛可能身高相同),在这些叠起来的牛的总高度>书架b的基础上,找出最小的差距(由于输入的数据会保证所有牛的高度相加>书架高度b,所以差距不为负) 还是看不懂题目? 举个栗子: 现在有五头牛高度分别为3 1 3 5 6,书架高度b=16,我们可以把五头牛都叠起来,总高度为18,差距为18-16=2,但…