1547: Rectangle

Time Limit: 1 Sec  Memory Limit: 256 MB
Submit: 996  Solved: 277
[Submit][Status][Web Board]

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

  1. 2
  2. 3
  3. 1 2
  4. 2 2
  5. 2 3
  6. 3
  7. 1 2
  8. 1 2
  9. 1 3

Sample Output

  1. 7
  2. 4
  3.  
  4. 题意:在 2*m 的矩形里面放若干宽度为12的矩形,问 m 最小要多大?
    题解:首先,对于宽度为2的矩形,我们直接加上就好了,这是它所需要的容积,对于宽度为 1 的矩形,我们长度先对其排序,这样就保证了选的矩形尽可能的可以并排放下,对sum/201背包,得到容量为sum/2
    背包能够放的最大容量m,用sum-dp[sum/2]即为所需最小容量。
  1. #include<stdio.h>
  2. #include<iostream>
  3. #include<string.h>
  4. #include<math.h>
  5. #include<algorithm>
  6. using namespace std;
  7. int x[],y[],v[];
  8. int dp[];
  9. int main()
  10. {
  11. int tcase,n;
  12. scanf("%d",&tcase);
  13. while(tcase--){
  14. scanf("%d",&n);
  15. int ans = ,cnt=,sum = ;
  16. for(int i=;i<=n;i++){
  17. scanf("%d%d",&x[i],&y[i]);
  18. if(x[i]==){
  19. ans+=y[i];
  20. }else{
  21. v[++cnt] = y[i];
  22. sum+=v[cnt];
  23. }
  24. }
  25. memset(dp,,sizeof(dp));
  26. sort(v+,v+cnt+);
  27. for(int i=;i<=cnt;i++){
  28. for(int j=sum/;j>=v[i];j--){
  29. dp[j] = max(dp[j],dp[j-v[i]]+v[i]);
  30. }
  31. }
  32. int res = ans+sum-dp[sum/];
  33. printf("%d\n",res);
  34. }
  35.  
  36. }
  1.  

csu 1547(01背包)的更多相关文章

  1. 51 nod 1007 正整数分组 (简单01背包) && csu 1547: Rectangle

    http://www.51nod.com/onlineJudge/questionCode.html#problemId=1007&noticeId=15020 求出n个数的和sum,然后用s ...

  2. CSU 1547 Rectangle(dp、01背包)

    题目链接:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1547 Description Now ,there are some rectang ...

  3. CSU 1547: Rectangle (思维题加一点01背包)

    1547: Rectangle Submit Page    Summary    Time Limit: 1 Sec     Memory Limit: 256 Mb     Submitted: ...

  4. hdu 2602 Bone Collector(01背包)

    题意:给出包裹的大小v,然后给出n块骨头的价值value和体积volume,求出一路下来包裹可以携带骨头最大价值 思路:01背包 1.二维数组(不常用 #include<iostream> ...

  5. UVALive 4870 Roller Coaster --01背包

    题意:过山车有n个区域,一个人有两个值F,D,在每个区域有两种选择: 1.睁眼: F += f[i], D += d[i] 2.闭眼: F = F ,     D -= K 问在D小于等于一定限度的时 ...

  6. POJ1112 Team Them Up![二分图染色 补图 01背包]

    Team Them Up! Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7608   Accepted: 2041   S ...

  7. Codeforces 2016 ACM Amman Collegiate Programming Contest A. Coins(动态规划/01背包变形)

    传送门 Description Hasan and Bahosain want to buy a new video game, they want to share the expenses. Ha ...

  8. 51nod1085(01背包)

    题目链接: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1085 题意: 中文题诶~ 思路: 01背包模板题. 用dp[ ...

  9. *HDU3339 最短路+01背包

    In Action Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

随机推荐

  1. 洛谷P1273 有线电视网 【树上分组背包】

    题目描述 某收费有线电视网计划转播一场重要的足球比赛.他们的转播网和用户终端构成一棵树状结构,这棵树的根结点位于足球比赛的现场,树叶为各个用户终端,其他中转站为该树的内部节点. 从转播站到转播站以及从 ...

  2. The 14th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple - C 暴力 STL

    What Kind of Friends Are You? Time Limit: 1 Second      Memory Limit: 65536 KB Japari Park is a larg ...

  3. 04-树4. Root of AVL Tree-平衡查找树AVL树的实现

    对于一棵普通的二叉查找树而言,在进行多次的插入或删除后,容易让树失去平衡,导致树的深度不是O(logN),而接近O(N),这样将大大减少对树的查找效率.一种解决办法就是要有一个称为平衡的附加的结构条件 ...

  4. 折腾到死:matlab7.0 安装

    matlab7.0应该是2004年的东西了吧,装起来相当费劲!为什么不用更高的版本呢?其实我也想,之前安装的2013a安装包就5个多G,安装完之后就十多个G了.我习惯将软件安装到C盘,可怜我那100G ...

  5. McNemar test麦克尼马尔检验

    sklearn实战-乳腺癌细胞数据挖掘(博主亲自录视频) https://study.163.com/course/introduction.htm?courseId=1005269003&u ...

  6. JavaSE的学习路线

    基于现阶段的JavaEE学习的对象,主要是趋向于Web的方向,主要就是说在JavaWeb的基础上进行进一步的开发和学习,下面我会将自己总结的对于自己的一点关于JavaEE学习路线会逐步讲解. 第一部分 ...

  7. (转)linux下vi命令修改文件及保存的使用方法

    进入vi的命令         vi filename :打开或新建文件,并将光标置于第一行首    vi n filename :打开文件,并将光标置于第n行首    vi filename :打开 ...

  8. Vue DatePicker和不可用

    input控件可以直接设置disabled为不可用状态: DatePicker要想不可编辑,设置readonly属性即可 <DatePicker type="date" v- ...

  9. hdu4699-Editor

    Sample Input 8 I 2 I -1 I 1 Q 3 L D R Q 2 Sample Output 2 3 发现IDLR四种操作都在光标处发生,且操作完成后光标至多移动1个位置,根据这种“ ...

  10. My deep learning reading list

    My deep learning reading list 主要是顺着Bengio的PAMI review的文章找出来的.包括几本综述文章,将近100篇论文,各位山头们的Presentation.全部 ...