POJ 3628 Bookshelf 2 0-1背包】的更多相关文章

Bookshelf 2 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9488   Accepted: 4311 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…
题意:给出n头牛的身高,以及一个书架的高度,问怎样选取牛,使得它们的高的和超过书架的高度最小. 将背包容量转化为所有牛的身高之和,就可以用01背包来做=== #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define maxn 2000005 using namespace std; ]; int main() { ,tmp=; scanf("%…
题目大意:FJ有n头奶牛,和一个高为h的架子,给出每头奶牛高度,求使奶牛叠加起来超过架子的最低高度是多少. 题目思路:求出奶牛叠加能达到的所有高度,并用dp[]保存,最后进行遍历,找出与h差最小的dp[]即所求答案. #include<cstdio> #include<stdio.h> #include<cstdlib> #include<cmath> #include<iostream> #include<algorithm> #i…
传送门: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: 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…
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…
本题解法非常多,由于给出的数据特殊性故此能够使用DFS和BFS,也能够使用01背包DP思想来解. 由于一般大家都使用DFS,这里使用非常少人使用的BFS.缺点是比DFS更加耗内存,只是长处是速度比DFS快. 当然也比DFS难写点: int N, B; int Height[21]; inline int mMin(int a, int b) { return a > b? b : a; } inline int mMax(int a, int b) { return a < b? b : a;…
Balance Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 10326   Accepted: 6393 题意:给你n个挂钩g个砝码  以及n个挂钩的距离天平中心距离(负的代表左边正的代表右边)g个砝码的重量. 要求输出能够令天平平衡的方法种类 解题思路     http://user.qzone.qq.com/289065406/blog/1299341345  非常具体 #include<iostream> #i…
题目链接: id=1636">POJ 1636 Prison rearrangement Prison rearrangement Time Limit: 3000MS   Memory Limit: 10000K Total Submissions: 2194   Accepted: 984 Description In order to lower the risk of riots and escape attempts, the boards of two nearby priso…