hdu----(1677)Nested Dolls(DP/LIS(二维))
Nested Dolls
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2704 Accepted Submission(s): 802
is the world’s most prominent collector of Russian nested dolls: he
literally has thousands of them! You know, the wooden hollow dolls of
different sizes of which the smallest doll is contained in the second
smallest, and this doll is in turn contained in the next one and so
forth. One day he wonders if there is another way of nesting them so he
will end up with fewer nested dolls? After all, that would make his
collection even more magnificent! He unpacks each nested doll and
measures the width and height of each contained doll. A doll with width
w1 and height h1 will fit in another doll of width w2 and height h2 if
and only if w1 < w2 and h1 < h2. Can you help him calculate the
smallest number of nested dolls possible to assemble from his massive
list of measurements?
the first line of input is a single positive integer 1 <= t <= 20
specifying the number of test cases to follow. Each test case begins
with a positive integer 1 <= m <= 20000 on a line of itself
telling the number of dolls in the test case. Next follow 2m positive
integers w1, h1,w2, h2, . . . ,wm, hm, where wi is the width and hi is
the height of doll number i. 1 <= wi, hi <= 10000 for all i.
3
20 30 40 50 30 40
4
20 30 10 10 30 20 40 50
3
10 30 20 20 30 10
4
10 10 20 30 40 50 39 51
2
3
2
//#define LOCAL
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
const int maxn=;
const int inf=0x3f3f3f3f;
int m; struct doll
{
int w,h;
bool operator <(const doll &a)const
{
if(w==a.w)
return h <a.h; //ÉýÐò
else
return w > a.w ; //½µÐò
}
}; doll aa[maxn],ans[maxn];
int dp[maxn]; int binary(doll v)
{
int l=,r=m,mid;
while(l<=r)
{
mid=l+((r-l)>>); //降序
if(ans[mid].h<=v.h)
l=mid+;
else
r=mid-;
}
return l;
} int LIS(doll a[],int n)
{
int i;
int res=;
for(i=;i<=n;i++)
{
ans[i].h=inf;
ans[i].w=inf;
}
for(i= ; i<=n ; i++){
dp[i]=binary(a[i]);
if(res<dp[i])res=dp[i];
if(ans[dp[i]].h>a[i].h&&ans[dp[i]].w>a[i].w){
ans[dp[i]].h=a[i].h;
ans[dp[i]].w=a[i].w;
}
}
return res;
} int main()
{
#ifdef LOCAL
freopen("test.in","r",stdin);
#endif int cas;
scanf("%d",&cas);
while(cas--){
scanf("%d",&m);
for(int i=;i<=m;i++){
scanf("%d%d",&aa[i].w,&aa[i].h);
}
sort(aa+,aa+m+);
printf("%d\n",LIS(aa,m));
}
return ;
}
hdu----(1677)Nested Dolls(DP/LIS(二维))的更多相关文章
- hdu 1677 Nested Dolls【贪心解嵌套娃娃问题】
链接: http://acm.hdu.edu.cn/showproblem.php?pid=1677 http://acm.hust.edu.cn/vjudge/contest/view.action ...
- HDU 1677 Nested Dolls
过了之后感觉曾经真的做过这样的类型的题. 之前一直非常疑惑二级排序的优先级问题,如今发现二级排序真的没有绝对的优先级. 对于此题,若按W排序,则有1到i件物品的W均小于等于第i+1件物品(设为A)的W ...
- HDU 1277 Nested Dolls
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1677 题意: 玩俄罗斯套娃,问最后至少还剩几个. 题解: 这题可以和拦截导弹做对比,因为这里是二维的 ...
- BestCoder Round #56 1002 Clarke and problem 1003 Clarke and puzzle (dp,二维bit或线段树)
今天第二次做BC,不习惯hdu的oj,CE过2次... 1002 Clarke and problem 和Codeforces Round #319 (Div. 2) B Modulo Sum思路差不 ...
- HDU 2888:Check Corners(二维RMQ)
http://acm.hdu.edu.cn/showproblem.php?pid=2888 题意:给出一个n*m的矩阵,还有q个询问,对于每个询问有一对(x1,y1)和(x2,y2),求这个子矩阵中 ...
- POJ3636Nested Dolls[DP LIS]
Nested Dolls Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8323 Accepted: 2262 Desc ...
- dp之二维背包poj1837(天平问题 推荐)
题意:给你c(2<=c<=20)个挂钩,g(2<=g<=20)个砝码,求在将所有砝码(砝码重1~~25)挂到天平(天平长 -15~~15)上,并使得天平平衡的方法数..... ...
- dp之二维背包poj2576
题意:有一群sb要拔河,把这群sb分为两拨,两拨sb数只差不能大于1,输出这两拨人的体重,小的在前面...... 思路:把总人数除2,总重量除2,之后你会发现就是个简单的二维背包,有两个限制..... ...
- Regionals 2014 >> Asia - Taichung 7003 - A Balance Game on Trees 树形DP + 二维费用背包
https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...
随机推荐
- pivot 与 unpivot 函数是SQL05新提供的2个函数 灰常灰常的实用
转自:http://blog.sina.com.cn/s/blog_5ef755720100cyo3.html pivot函数: create table test(id int,name varch ...
- .Net需要掌握的知识
一.C#开发 1.C#基础 变量定义 如何变量的初始化 变量的作用域 常量 字符串处理 使用正则表达式 什么是CTS类型?数据类型如何分类以及各个数据类型范围 类型的转化分类 显式转换何隐式转化如何区 ...
- 【CSS】最全的CSS浏览器兼容问题
CSS对浏览器的兼容性有时让人很头疼,或许当你了解当中的技巧跟原理,就会觉得也不是难事,从网上收集了IE7,6与Fireofx的兼容性处理方法并 整理了一下.对于web2.0的过度,请尽量用xhtml ...
- [Java解惑]类
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
- yii 常用路径
yii::app()->homeurl //主页的网址 yii系统变量. //得到proteced目录的物理路径 Yii::app()->basePath; 调用YII框架中jquery: ...
- EntityManager方法简介
EntityManager 是用来对实体Bean 进行操作的辅助类.他可以用来产生/删除持久化的实体Bean,通过主键查找实体bean,也可以通过EJB3 QL 语言查找满足条件的实体Bean.实体B ...
- iOS - TouchLock 手势解锁
1.手势解锁的创建 代码封装见 QExtension QLockView.h #import <UIKit/UIKit.h> @interface QLockView : UIView / ...
- 教你如何拔取百度地图POI兴趣点
教你如何拔取百度地图POI兴趣点 通过聚合数据提供的接口,获取百度地图的POI兴趣点,并存储至数据库中. 实现: 1.聚合数据百度POI接口说明 调用聚合数据,首先得注册聚合.聚合数据提供的百度地 ...
- Xpert 调优
-- 10046 event 可以定义 SQL TRACE 级别 /* || 默认的10046级别跟 SQL TRACE 一样, 另外还有一些级别: || level 1: SQL Tracing | ...
- Win7_64位使用Mysql Odbc
1.首先不能安装Mysql Odbc 64位,因为我们的Mysql是32位,使用Mysql Odbc 64位连接Mysql 32位,报错:驱动程序与应用程序之间的体系结构不匹配. 2.要安装Mysql ...