CSU 1547 背包
来源:互联网 发布:淘宝 省钱快报 编辑:程序博客网 时间:2024/06/04 19:35
Description
Now ,there are some rectangles. The area of these rectangles is 1* x or 2 * x ,and now you need find a big enough rectangle( 2 * m) so that you can put all rectangles into it(these rectangles can't rotate). please calculate the minimum m satisfy the condition.
Input
There are some tests ,the first line give you the test number.
Each test will give you a number n (1<=n<=100)show the rectangles number .The following n rows , each row will give you tow number a and b. (a = 1 or 2 , 1<=b<=100).
Output
Each test you will output the minimum number m to fill all these rectangles.
Sample Input
231 22 22 331 21 21 3
Sample Output
74
题意:给你一些小块只有1*X,或者2*X,问使用一个2*M的大方块装下这些小方块,M只至少要多大?
题解:2*X直接累加,1*X的加起来和为V,创建一个容量为V/2的背包,尽可能的装进这个背包最小代价就是V-DP[V/2]啦。
#include<iostream>#include<cstring>#include<cstdio>#include<algorithm>#include<set>#include<vector>#include<map>using namespace std;#define N 20000struct point{int x,y;point (int _x,int _y):x(_x),y(_y){}point(){}};vector<point>eg;int dp[N];int main(){#ifdef CDZSCfreopen("i.txt","r",stdin);#endifint n,t,x,y;scanf("%d",&t);while(t--){eg.clear();memset(dp,0,sizeof(dp));int sum=0,v=0;scanf("%d",&n);for(int i=0;i<n;i++){scanf("%d%d",&x,&y);if(x==2){sum+=y;}else{v+=y;eg.push_back(point(x,y));}}for(int i=0;i<eg.size();i++){for(int j=v/2;j>=eg[i].y;j--){dp[j]=max(dp[j],dp[j-eg[i].y]+eg[i].y);}}printf("%d\n",v-dp[v/2]+sum);}return 0;}
- CSU 1547 背包
- csu 1547: Rectangle (01背包)
- CSU 1547 Rectangle(01背包)
- csu 1547: Rectangle (01背包)
- CSU 1547-Rectangle(0-1背包)
- csu(背包的变形题)
- CSU 1086 超市购物 分组背包问题
- CSU 1447: Mario Kart 背包+最短路
- CSU 1580Outing 强连通+背包
- CSU 1671 经营小卖部 (完全背包 DP)
- dp --- CSU 1547: Rectangle
- CSU 1547: Rectangle
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- Linux命令-权限设置
- 有向图(2)--深度优先搜索&&广度优先搜索
- SpringMVC深度探险(一) —— SpringMVC前传
- Mangos Zero 编译安装
- reg修改网页收藏夹存储位置
- CSU 1547 背包
- 初识C语言
- 用scheme语言实现SPFA算法(单源最短路)
- ubuntu12.04中shell脚本无法使用source的原因及解决方法
- head标签
- LeetCode 之 Palindrome Linked List
- c++中多参数
- 为学无他,争千秋勿争一日
- 黑马程序员-Java的内部类