Nested Dolls

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2704    Accepted Submission(s): 802

Problem Description
Dilworth
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?
 
Input
On
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.
 
Output
For each test case there should be one line of output containing the minimum number of nested dolls possible.
 
Sample Input
4
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
 
Sample Output
1
2
3
2
 
Source
 
题意:  给你N个木偶娃娃,每一个娃娃都有一定的高度,和宽度,然后娃娃的内部是空心的,现在要你把小的娃娃放到大娃娃的肚子去,然后问最后剩下几个娃娃..
  有点像盒子套盒子意思,处理方法。采用DP
LIS二维处理:  现将一个属性比如 height作为标准,从大到小排序,遇到相等的width,则对另一个属性h,从小到大排序。
代码:
 //#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(二维))的更多相关文章

  1. hdu 1677 Nested Dolls【贪心解嵌套娃娃问题】

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=1677 http://acm.hust.edu.cn/vjudge/contest/view.action ...

  2. HDU 1677 Nested Dolls

    过了之后感觉曾经真的做过这样的类型的题. 之前一直非常疑惑二级排序的优先级问题,如今发现二级排序真的没有绝对的优先级. 对于此题,若按W排序,则有1到i件物品的W均小于等于第i+1件物品(设为A)的W ...

  3. HDU 1277 Nested Dolls

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1677 题意: 玩俄罗斯套娃,问最后至少还剩几个. 题解: 这题可以和拦截导弹做对比,因为这里是二维的 ...

  4. 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思路差不 ...

  5. HDU 2888:Check Corners(二维RMQ)

    http://acm.hdu.edu.cn/showproblem.php?pid=2888 题意:给出一个n*m的矩阵,还有q个询问,对于每个询问有一对(x1,y1)和(x2,y2),求这个子矩阵中 ...

  6. POJ3636Nested Dolls[DP LIS]

    Nested Dolls Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8323   Accepted: 2262 Desc ...

  7. dp之二维背包poj1837(天平问题 推荐)

    题意:给你c(2<=c<=20)个挂钩,g(2<=g<=20)个砝码,求在将所有砝码(砝码重1~~25)挂到天平(天平长  -15~~15)上,并使得天平平衡的方法数..... ...

  8. dp之二维背包poj2576

    题意:有一群sb要拔河,把这群sb分为两拨,两拨sb数只差不能大于1,输出这两拨人的体重,小的在前面...... 思路:把总人数除2,总重量除2,之后你会发现就是个简单的二维背包,有两个限制..... ...

  9. 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 ...

随机推荐

  1. Linux常见问题的处理方法(长期更新)

    一.使用sudo命令时xxx is not in the sudoers file. This incident will be reported. 1.su -,输入root的密码完成身份切换. 2 ...

  2. vim 跳到指定行

    在编辑模式下输入 ngg 或者 nG n为指定的行数(如25) 25gg或者25G 跳转到第25行. 在命令模式下输入行号n : n 如果想打开文件即跳转 vim +n FileName 查看当然光标 ...

  3. MYSQL 表级锁 行级锁 页面锁区别

    myisam存储引擎默认是表级锁 innodb存储引擎默认是行级锁 DBD存储引擎默认是页面锁   表级锁:开销小,加锁快:不会出现死锁:锁定粒度大,发出锁冲突的概率最高,并发度最低.行级锁:开锁大, ...

  4. Redis配置文件之————redis.conf配置及说明

    基本设置 1. 备释当配置中需要配置内存大小时,可以使用 1k, 5GB, 4M 等类似的格式,其转换方式如下(不区分大小写):1k =< 1000 bytes1kb =< 1024 by ...

  5. Nexus4铃声目录

    1. 我的铃声 是通过下面的命令 传到手机上面去的: “ adb push fringe_01_long.mp3 /sdcard/ZC/ adb push fringe_02_short.mp3 /s ...

  6. RAR暴破

    1. 网上稍微搜索了一下,貌似一个叫 "ARPR"的软件 出现的频率较高. 2. http://jingyan.baidu.com/article/a948d651b954a90a ...

  7. 学习日记day8:移动端页面流程优化

    一:切图 1:切那些(移动端能不用图片就不用图片:logo单独切因为要带链接) 2:普通切(快捷键:复制到新图层  选中 复制 新建 粘贴 保存)  3:类似切 (选中多个图层  矩形框多选  选择工 ...

  8. 构建maven项目3

    1.1.创建Jave Project 1.使用mvn archetype:generate命令,如下所示: mvn archetype:generate -DgroupId=com.mycompany ...

  9. Android 随想录之 Android 系统架构

    应用层(Application) Android 的应用层由运行在 Android 设备上的所有应用程序共同构成(系统预装程序以及第三方应用程序). 系统预装应用程序包含拨号软件.短信.联系人.邮件客 ...

  10. supervisord

    [简介] supervisord的官网:http://supervisord.org.看懂英文的可以不用看我的博客,直接看文档就行了,文档写得非常好.点个赞!! Supervisor是一个客户/服务器 ...