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. CodeForces 552C Vanya and Scales

    Vanya and Scales Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u S ...

  2. CodeForces 146A Lucky Ticket

    Lucky Ticket Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submi ...

  3. Cheatsheet: 2014 03.01 ~ 03.31

    .NET Should I be concerned about PDB files? async and await -Simplified-Internals Web Performance tr ...

  4. 通过桥接虚拟网卡使VMWare和宿主机实现双向通讯

    0.为什么选择虚拟网卡和桥接模式 首先虚拟机网络设置为NAT,虚拟机实现上网是很方便的,但是宿主机访问虚拟机就比较麻烦了(需要单独配置端口转发),桥接就能很好的解决这个问题,桥接模式会把虚拟机当做宿主 ...

  5. DEV界面皮肤

    1.添加一个 2.添加引用: 3.添加一个SkinTools类 public class SkinTools { /// <summary> /// 在Program中调用 /// < ...

  6. 关于float的感悟

    给元素设置了float样式后,最终的结果是: 1:这个元素漂浮起来, 2:其他的元素位置可以视为 这个元素不存在 的时候的位置:但是float样式还是对整个页面有所影响 3:float的影响就是他附近 ...

  7. Python渗透测试工具合集

    摘自:http://www.freebuf.com/tools/94777.html 如果你热爱漏洞研究.逆向工程或者渗透测试,我强烈推荐你使用 Python 作为编程语言.它包含大量实用的库和工具, ...

  8. set集合的用法总结(转)

    python的set和其他语言类似, 是一个无序不重复元素集, 基本功能包括关系测试和消除重复元素. 集合对象还支持union(联合), intersection(交), difference(差)和 ...

  9. Simulating a Fetch robot in Gazebo

    Installation Before installing the simulation environment, make sure your desktop is setup with a st ...

  10. js 定时器的使用。 setInterval()

    我需要实现的功能是:点击发送按钮,会出现 “已发送60s后可点击重发”,并且,60s 这个数字是随时变化的,60,59,58,57....0,然后再次返回到 发送 按钮. 类似效果,可参考  360首 ...