Nested Dolls
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 8630   Accepted: 2367

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

不是很懂这个排序

上题是最长严格递减子序列,这题是最长不上升子序列

#include<cstdio>
#include<iostream>
#include<algorithm> #define N 20001 using namespace std; struct node
{
int a,b;
}e[N]; int s,f[N]; bool cmp(node p,node q)
{
if(p.a!=q.a) return p.a<q.a;
return p.b>q.b;
} int find(int w)
{
int l=,r=s,mid,tmp=-;
while(l<=r)
{
mid=l+r>>;
if(f[mid]<w) tmp=mid,r=mid-;
else l=mid+;
}
return tmp;
} int main()
{
int T,n,pos;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(int i=;i<=n;i++) scanf("%d%d",&e[i].a,&e[i].b);
sort(e+,e+n+,cmp);
f[s=]=2e9;
for(int i=;i<=n;i++)
if(e[i].b<=f[s]) f[++s]=e[i].b;
else
{
pos=find(e[i].b);
if(pos>) f[pos]=e[i].b;
}
printf("%d\n",s);
}
}

poj 3636的更多相关文章

  1. 物联网学生科协第三届H-star现场编程比赛

    问题 A: 剪纸片 时间限制: 1 Sec 内存限制: 128 MB 题目描写叙述 这是一道简单的题目,假如你身边有一张纸.一把剪刀.在H-star的比赛现场,你会这么做: 1. 将这张纸剪成两片(平 ...

  2. POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理

    Halloween treats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7644   Accepted: 2798 ...

  3. POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理

    Find a multiple Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7192   Accepted: 3138   ...

  4. POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治

    The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22286 ...

  5. POJ 1753. Flip Game 枚举or爆搜+位压缩,或者高斯消元法

    Flip Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 37427   Accepted: 16288 Descr ...

  6. POJ 3254. Corn Fields 状态压缩DP (入门级)

    Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9806   Accepted: 5185 Descr ...

  7. POJ 2739. Sum of Consecutive Prime Numbers

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050 ...

  8. POJ 2255. Tree Recovery

    Tree Recovery Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11939   Accepted: 7493 De ...

  9. POJ 2752 Seek the Name, Seek the Fame [kmp]

    Seek the Name, Seek the Fame Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17898   Ac ...

随机推荐

  1. plsql 永久注册码

    注册码:Product Code:4t46t6vydkvsxekkvf3fjnpzy5wbuhphqzserial Number:601769 password:xs374ca 可用

  2. input value="值栈的值"

    <input type="text" value="<s:property value="myp.begintime"/>" ...

  3. DP--HDU 1003(最大子串和)

    问题描述:          给定整数A1, A2,--AN (可能有负数),求I到j的最大值. 例如:          -2, 11, -4, 13, -5, -2时答案为20 对于这个问题的算法 ...

  4. HDU 5207 Greatest Greatest Common Divisor

    题目链接: hdu:http://acm.hust.edu.cn/vjudge/problem/visitOriginUrl.action?id=153598 bc(中文):http://bestco ...

  5. JavaScript DOM编程艺术学习笔记-第一章JavaScript简史

    一,JavaScript的起源 JavaScript是Netscape与Sun公司合作开发,它是一种脚本语言,通常只能通过Web浏览器去完成一些操作.JavaScript为程序员提供了一些操控Web浏 ...

  6. Java try catch

    /*   异常处理的捕捉形式: 这是可以对异常进行针对性处理的方式.   具体格式是: try { //需要被检测异常的代码. } catch(异常类 变量)//该变量用于接收发生的异常对象 { // ...

  7. jQuery的2把利器

    <!-- $是一个函数,首先是给window添加$,然后该值是一个函数,函数返回的值是对象.1. jQuery核心函数 * 简称: jQuery函数($/jQuery) * jQuery库向外直 ...

  8. Hash(散列函数)简单应用引出解决散列冲突的四种方法

    商店允许顾客通过电话订购商品,并在几天后上门自取.商店的数据库使用客户的电话号码作为其检索的关键字(客户知道自己的电话号码,而且这些电话关键字几乎是唯一的).如何组织商店的数据库,以允许更加高效的进行 ...

  9. PAT 甲级 1144 The Missing Number

    https://pintia.cn/problem-sets/994805342720868352/problems/994805343463260160 Given N integers, you ...

  10. get_list_by_where

    /** * 查询数据 * @param $param * @param bool $get_rows 或者总数 * @param bool $get_one 或者一条记录 * @param bool ...