POJ 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…
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…
POJ 3211 Washing Clothes(01背包) http://poj.org/problem?id=3211 题意: 有m (1~10)种不同颜色的衣服总共n (1~100)件.Dearboy和她的girlfriend两个人要一起洗完所有衣服,为了预防色彩混合,他们每次仅仅能同一时候洗同一种颜色的衣服,给出洗完每件衣服所需的时间time和它的颜色color,求出Dearboy和她的girlfriend最少用多少时间能洗完毕所有衣服. 分析: 因为每种颜色的衣服是分开洗的, 所以我们…
题意:给出n头牛的身高,以及一个书架的高度,问怎样选取牛,使得它们的高的和超过书架的高度最小. 将背包容量转化为所有牛的身高之和,就可以用01背包来做=== #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define maxn 2000005 using namespace std; ]; int main() { ,tmp=; scanf("%…
http://poj.org/problem?id=3628 01背包 #include <cstdio> #include <iostream> #include <cstring> #include <algorithm> #define maxn 21 #define ll long long using namespace std; ll h[maxn]; int n; ll b; ll dp[]; ll max1(ll a,ll b) { retu…
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…
题目链接:http://poj.org/problem?id=2184 Cow Exhibition Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9479   Accepted: 3653 Description "Fat and docile, big and dumb, they look so stupid, they aren't much  fun..."  - Cows with Guns by…
Charm Bracelet Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 38909   Accepted: 16862 Description Bessie has gone to the mall's jewelry store and spies a charm bracelet. Of course, she'd like to fill it with the best charms possible fro…