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

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 h= 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 w1h1,w2h2, ... ,wmhm, where wi is the width and hi is the height of doll number i. 1 ≤ wihi ≤ 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

------------------------------------
貌似有一种很厉害的东西叫Dilworth定理
最少的chain个数等于最大的antichain的大小
按照w从小到大排序,剩下考虑h,chain应该是严格单增
最少几个,antichain,不就是导弹拦截的第二问,最长不下降子序列
要注意的是w相同时h大的放在前,因为w相同嵌套是违法的,WA好几次
 
//
// main.cpp
// poj3636
//
// Created by abc on 16/8/30.
// Copyright © 2016年 abc. All rights reserved.
// #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int N=,INF=1e9;
struct data{
int w,h;
}da[N];
bool cmpda(data a,data b){
if(a.w>b.w) return ;
if(a.w<b.w) return ;
if(a.w==b.w) return a.h>b.h?:;
return ;
}
int t,n;
int f[N],g[N],a[N];
bool cmp(int a,int b){
return a>b;
}
int dp(){
int ans=;
sort(da+,da++n,cmpda);
memset(f,,sizeof(f));
for(int i=;i<=n;i++) g[i]=-INF,a[i]=da[i].h;
for(int i=;i<=n;i++){
int k=upper_bound(g+,g++n,a[i],cmp)-g;
f[i]=k;
g[k]=a[i];
ans=max(ans,f[i]);
}
return ans;
} int main(int argc, const char * argv[]) {
scanf("%d",&t);
for(int i=;i<=t;i++){
scanf("%d",&n);
for(int i=;i<=n;i++) scanf("%d%d",&da[i].w,&da[i].h);
printf("%d\n",dp());
}
return ;
}
 

POJ3636Nested Dolls[DP LIS]的更多相关文章

  1. hdu----(1677)Nested Dolls(DP/LIS(二维))

    Nested Dolls Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  2. 洛谷P1108 低价购买[DP | LIS方案数]

    题目描述 “低价购买”这条建议是在奶牛股票市场取得成功的一半规则.要想被认为是伟大的投资者,你必须遵循以下的问题建议:“低价购买:再低价购买”.每次你购买一支股票,你必须用低于你上次购买它的价格购买它 ...

  3. hdu----(1257)最少拦截系统(dp/LIS)

    最少拦截系统 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

  4. hdu--(1025)Constructing Roads In JGShining's Kingdom(dp/LIS+二分)

    Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65 ...

  5. hdu 4352 "XHXJ's LIS"(数位DP+状压DP+LIS)

    传送门 参考博文: [1]:http://www.voidcn.com/article/p-ehojgauy-ot.html 题解: 将数字num字符串化: 求[L,R]区间最长上升子序列长度为 K ...

  6. BZOJ.1109.[POI2007]堆积木Klo(DP LIS)

    BZOJ 二维\(DP\)显然.尝试换成一维,令\(f[i]\)表示,强制把\(i\)放到\(a_i\)位置去,现在能匹配的最多数目. 那么\(f[i]=\max\{f[j]\}+1\),其中\(j& ...

  7. HDU 4352 XHXJ's LIS 数位dp lis

    目录 题目链接 题解 代码 题目链接 HDU 4352 XHXJ's LIS 题解 对于lis求的过程 对一个数列,都可以用nlogn的方法来的到它的一个可行lis 对这个logn的方法求解lis时用 ...

  8. Codeforces.264E.Roadside Trees(线段树 DP LIS)

    题目链接 \(Description\) \(Solution\) 还是看代码好理解吧. 为了方便,我们将x坐标左右反转,再将所有高度取反,这样依然是维护从左到右的LIS,但是每次是在右边删除元素. ...

  9. HDU 4352 - XHXJ's LIS - [数位DP][LIS问题]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4352 Time Limit: 2000/1000 MS (Java/Others) Memory Li ...

随机推荐

  1. Web前端开发工具总结

    前端开发工具: web前端开发乃及其它的相关开发, 推荐sublime text, webstorm(jetbrains公司系列产品)这两个的原因在于,有个技术叫emmet, http://docs. ...

  2. 在SharePoint 2013中显示“以其他用户身份登录”

    在我新建了SharePoint 2013的网站后, 发现界面与2010有一些不同,比如缺少了“以其他用户身份登录”,这给我的测试带来很大不便. 在找了一些国外网站后,终于找到了解决方法 第一步: 找到 ...

  3. Sharepoint学习笔记—习题系列--70-576习题解析 -(Q63-Q65)

    Question 63You are designing a SharePoint 2010 implementation that will be used by a company with a ...

  4. Jquery分页功能

    Jquery代码 /// <reference path="jquery-1.9.1-vsdoc.js" />//锚点var anchor="#apage&q ...

  5. Scrum三大角色特点

    灵感来自于一段冷笑话: 一天,一头猪和一只鸡在路上散步,鸡看了一下猪说,“嗨,我们合伙开一家餐馆怎么样?”,猪回头看了一下鸡说,“好主意,那你准备给餐馆起什么名字呢?”,鸡想了想说“餐馆名字叫火腿和鸡 ...

  6. 【C语言】C语言常量和变量

    目录: [常量]   · 定义   · 分类   · 特殊字符型常量 [变量]   · 定义   · 定义变量   · 变量的使用   · 变量使用注意   · 变量常见问题 1.常量 · 定义 常量 ...

  7. 基于SolrCloud的内容搜索和热点推送

    ➠更多技术干货请戳:听云博客 什么是热点 我认为热点有时效性和受众面 用户关注从低到高再到低的内容 .有公共热点和分类热点.例如医辽养老全民关注,科技汽车等只有特定的人群关注. 推送的条件 搜索频次达 ...

  8. linux下 yum 安装mysql和卸载

    1.查看有没有安装过: yum list installed mysql* rpm -qa | grep mysql* 2.查看有没有安装包: yum list mysql* 3.安装mysql客户端 ...

  9. lumen Console Commands

    1.在app->Console->Commands中新增类 继承  Illuminate\Console\Command <?php namespace App\Console\Co ...

  10. ios app响应background,foreground 事件实现

    1 通过AppDelegate 实现 App进入后台事件方法 - (void)applicationDidEnterBackground:(UIApplication *)application AP ...