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 ...
随机推荐
-
Coursera台大机器学习课程笔记3 – 机器学习的可能性
提纲: 机器学习为什么可能? 引入计算橙球概率问题 通过用Hoeffding's inequality解决上面的问题,并得出PAC的概念,证明采样数据学习到的h的错误率可以和全局一致是PAC的 将得到 ...
-
[转载]win32 计时器使用
在工业生产控制系统中,有许多需要定时完成的操作,如定时显示当前时间,定时刷新屏幕上的进度条,上位机定时向下位机发送命令和传送数据等.特别是在对控制性能要求较高的实时控制系统和数据采集系统中,就更需要精 ...
-
BZOJ3640 : JC的小苹果
设$f[i][j]$表示$hp$为$i$,在$j$点的概率,$d[i]$表示$i$的度数,$w[i]$表示经过$i$点要扣掉的血量. 对于$j$到$k$这条边,$f[i-w[k]][k]+=\frac ...
-
ArcGIS API for Silverlight 调用GP服务绘制等值面
原文:ArcGIS API for Silverlight 调用GP服务绘制等值面 GP服务模型如下图: 示例效果图片如下:
-
dom 侧栏分享
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
-
ueditor 编辑器再thinkphp中使用 解决转义问题
在前台common.php文件中加入下面的函数就可以解决了 <?php //取消thinkphp里面的转义 if (get_magic_quotes_gpc()) { function stri ...
-
rman的conver方法拷贝ASM文件
rman中的conver命令主要用户跨平台传输表空间,也可以完成从ASM何本地文件系统中拷贝文件,比用dbms_file_transfer方法要简单 从ASM拷贝到文件系统: 拷贝表空间 在拷贝表空间 ...
-
Java_HelloWorld
Java_HelloWorld 一.JDK安装与环境变量的设置 可以在甲骨文公司的主页上直接下载. 链接:http://www.oracle.com/technetwork/java/javase/d ...
-
CentOS6.5配置 cron
CentOS6.5配置 cron 任务 - mengjiaoduan的博客 - CSDN博客https://blog.csdn.net/mengjiaoduan/article/details/649 ...
-
PreparedStement 用户登录!
一.准备工作 在qy66数据库下,新建一个denglu表.添加 name password . package cn.zhouzhou; import java.sql.Connection; im ...