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 ...
随机推荐
- CodeForces 483C Diverse Permutation
Diverse Permutation Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64 ...
- Cheatsheet: 2013 12.17 ~ 12.31
.NET Introducing ASP.NET Web API Throttling handler C# async and await: A Deeper Dive PARALLEL PROGR ...
- Excel2003命令栏操作
Excel2003个人觉得应该把它抛掉不管了,但还是没忍住想看下它里面的东东. 一.先列出一些重要对象 Commandbars:命令栏集合 ...
- 在Spring中使用脚本
Spring支持3中不同的脚本语言(看来支持地还挺多的嘛):JRuby.Groovy和BeanShell. 这三个都是java社区的脚本语言(反正到目前为止我一个都没用过,可见我有多挫). JRuby ...
- SQL判断临时表是否存在
IF EXISTS(select * from tempdb..sysobjects where id=object_id('tempdb..#tb')) BEGIN DROP TABLE #tb E ...
- HUD 2203 亲和串
HUD 2203 亲和串 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768K (Java/Others) [题目描述 - ...
- 在VNC中Xfce4中Tab键失效的解决方法
说明 在Ubuntu Server 14.04上安装了xfce4桌面环境,但是却发现在终端中Tab键不能自动补齐(但是Ctrl + I 仍然可以用). 出现这种情况的原因是,由于Tab键的功能被窗口快 ...
- PLSQL Developer连接远程Oracle方法(非安装客户端)
Oracle比较麻烦,通常需要安装oracle的客户端才能实现.通过instantclient可以比较简单的连接远程的Oracle. 1.新建目录D:\Oracle_Cleint用于存放相关文件,新建 ...
- oracle查询一个数据库有几张表
登录sys用户后通过user_tables表查看当前用户下表的张数.sql:conn / as sysdba;sql:select count(*) from user_tables ;解释:必须是登 ...
- /dev/sda3: UNEXPECTED INCONSISTENCY; RUN fsck MANUALLY
系统强制断电后,出现以下错误: /dev/sda3: UNEXPECTED INCONSISTENCY; RUN fsck MANUALLY 启动系统后在字符界面有两个选项,输入root密码进入维护模 ...