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. vue视频插件VLC

    VLC 仅支持windows下特定版本火狐浏览器--Firefox_ESR_55.3 <template> <object type='application/x-vlc-plugi ...

  2. 使用C和C++实现“电梯”的区别

    C 面向过程:       该电梯不允许未卜先知,故程序需逐条处理乘客请求并更新当前各变量状态.       如何获得最短时间:是否立即响应请求,计算出不同决策下的总时间,并进行比较,然后选择最短时间 ...

  3. 软工实践-Alpha 冲刺 (7/10)

    队名:起床一起肝活队 组长博客:博客链接 作业博客:班级博客本次作业的链接 组员情况 组员1(队长):白晨曦 过去两天完成了哪些任务 描述: 已经解决登录注册等基本功能的界面. 完成非功能的主界面制作 ...

  4. Learn Docker(一)—软件安装与常规操作

    一.安装Docker Windows平台 在Windows10 X64专业版上可以直接下载Docker原生应用进行安装,在控制面板的程序与功能里启用Hyper-v,之后就可以运行docker程序啦. ...

  5. 团队作业4——第一次项目冲刺(Alpha版本)第二次

    一.会议内容 各人进行下一步工作 发现沟通流程问题并解决 二.各人工作 成员 计划任务 遇见难题 贡献比 塗家瑜(组长) 后端逻辑处理 无 1 张新磊 数据库搭建 无 1 姚燕彬 测试计划编写 无 1 ...

  6. lintcode-81-数据流中位数

    81-数据流中位数 数字是不断进入数组的,在每次添加一个新的数进入数组的同时返回当前新数组的中位数. 说明 中位数的定义: 中位数是排序后数组的中间值,如果有数组中有n个数,则中位数为A[(n-1)/ ...

  7. 技嘉主板+AMD CPU开启CPU虚拟化方法

    硬件环境:技嘉AB350+AMD Ryzen 5 1600X 由于安装虚拟机的需要,所以要开启CPU的虚拟化. 首先进入BIOS. 然后如图:(M.I.T-高级频率设定-CPU超频进阶设置-SVM M ...

  8. PAT 甲级 1129 Recommendation System

    https://pintia.cn/problem-sets/994805342720868352/problems/994805348471259136 Recommendation system ...

  9. Spring Security 入门详解

    序:本文主要参考 spring实战 对里面的知识做一个梳理 1.Spring Security介绍 Spring Security是基于spring的应用程序提供声明式安全保护的安全性框架,它提供了完 ...

  10. Spring 学习 3- AOP

    什么是AOP aop就是纵向的编程,业务1和业务2都需要一个共同的操作,与其往每个业务中都添加同样的代码,不如写一遍代码,让两个业务共同使用这段代码. spring中面向切面编程用的是代理模式,它的实 ...