Rectangle(csu)
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
2
3
1 2
2 2
2 3
3
1 2
1 2
1 3
Sample Output
7
4
Hint
只能说经验不足,不知道这道题是0 1背包,背包大小 sum/2
记忆化搜索
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <set>
using namespace std;
int num[120];
int n;
int maxhave[10000][120];
int getmax(int sum,int n)
{
int res;
if(maxhave[sum][n] != -1) res = maxhave[sum][n];
else if(n == 1){
if(sum >= num[n]) res = num[n];
else res = 0;
}
else if(sum >= num[n]){
res = max(getmax(sum - num[n],n - 1) + num[n],getmax(sum,n - 1));
}
else res = getmax(sum,n - 1);
maxhave[sum][n] = res;
return res;
}
int main()
{
int t;
cin>>t;
while(t--){
memset(maxhave,-1,sizeof maxhave );
cin>>n;
int ans,sum;
int a,b,c=1;
ans = sum = 0;
for(int i = 1; i <= n; ++i)
{
cin>>a>>b;
if(a == 2) ans += b;
else { num[c++] = b;sum += b; }
}
--c;
int tmp = getmax(sum/2,c);
ans = ans + max(tmp,sum-tmp);
cout<<ans<<endl;
}
}
Rectangle(csu)的更多相关文章
- dp --- CSU 1547: Rectangle
Rectangle Problem's Link: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1547 Mean: 给你一些宽为1或2 的木 ...
- CSU 1547 Rectangle(dp、01背包)
题目链接:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1547 Description Now ,there are some rectang ...
- CSU 1547: Rectangle (思维题加一点01背包)
1547: Rectangle Submit Page Summary Time Limit: 1 Sec Memory Limit: 256 Mb Submitted: ...
- CSU - 1547 Rectangle —— DP(01背包)
题目链接:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1547 题解: 关键是怎么处理长度为1的长方形.当长度为1的长方形的个数cnt> ...
- 51 nod 1007 正整数分组 (简单01背包) && csu 1547: Rectangle
http://www.51nod.com/onlineJudge/questionCode.html#problemId=1007¬iceId=15020 求出n个数的和sum,然后用s ...
- [LeetCode] Perfect Rectangle 完美矩形
Given N axis-aligned rectangles where N > 0, determine if they all together form an exact cover o ...
- [LeetCode] Max Sum of Rectangle No Larger Than K 最大矩阵和不超过K
Given a non-empty 2D matrix matrix and an integer k, find the max sum of a rectangle in the matrix s ...
- [LeetCode] Smallest Rectangle Enclosing Black Pixels 包含黑像素的最小矩阵
An image is represented by a binary matrix with 0 as a white pixel and 1 as a black pixel. The black ...
- [LeetCode] Rectangle Area 矩形面积
Find the total area covered by two rectilinear rectangles in a2D plane. Each rectangle is defined by ...
随机推荐
- iOS多线程编程之NSThread的使用
目录(?)[-] 简介 iOS有三种多线程编程的技术分别是 三种方式的有缺点介绍 NSThread的使用 NSThread 有两种直接创建方式 参数的意义 PS不显式创建线程的方法 下载图片的例子 ...
- ASINetworkQueues(经典2)
ASINetworkQueues, 它的delegate提供更为丰富的功能 提 供的更多的回调方法如下: a,requestDidStartSelector,请求发起时会调此方法,你可以在此方法中跟据 ...
- AppStore下载失败使用已购页面再试一次解决方法
AppStore载失败 使用已购页面再试一次解决方法 工具/原料 Mac OS 方法/步骤 1.大家可以先试试更改系统 DNS 的方法,由于苹果的 App Store 应用商店在国外,所以 DNS 如 ...
- Innodb之拷贝InnoDB表从一服务器到另一台服务器
将Innodb类型的表从一台服务器拷贝到另一台服务器,或从一个库拷贝到另一个库. 前提是:innodb_file_per_table =ON. 1 先在目标服务器(库)上创建一个相同的表结构. 如: ...
- WhaleSong
Chasingwaves by myself in theocean of endless sorrow Makingwishes that i will find myherd tomorrow 5 ...
- DB2 SQL Mixed data in character strings
Mixed character data and graphic data are always allowed for Unicode, but for EBCDIC and ASCII, the ...
- NYOJ题目769乘数密码
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAsQAAAJYCAIAAADqk2fsAAAgAElEQVR4nO3dPVLrytbG8XcS5AyEWA
- Jmeter中通过BeanShell获取当前时间
第一步编写需要的java类: 第二步:将编写好的java类打包成jar包 第三步:将jar包放到\apache-jmeter-2.13\lib\ext下面 第四步:在Jmeter中通过BeanShel ...
- Jquery自定义图片上传插件
1 概述 编写后台网站程序大多数用到文件上传,可是传统的文件上传控件不是外观不够优雅,就是性能不太好看,翻阅众多文件上传控件的文章,发现可以这样去定义一个文件上传控件,实现的文件上传的效果图如下: 2 ...
- 【JAVA正则表达式】
一.String类. java.lang.Object |--java.lang.String 常用方法: String replaceAll(String regex, String replac ...