/*题意:有n个矩形,用长和宽表示,如果一个的长和宽都比另一个小,那么这个嵌放在另一个中
所以先对w从大到小排序,w一样的按h从小到大排序,那么就从后面的箱子往前找,只要前面找到一个人h比自己大的就放入c[j]=p[i].h;
否则如果自己的h比前面的都大,那么必定询问到c所存的递增序列的长度+1处,那么个数加1,长度加1,把此事的h放在在c的末端
这个过程和最大递增子序列的找值过程类似,但是并不是求最长递增,只是利用这个过程,所以二分查找稍微有些改变,如果还是按照
最长公共子序列的二分查找,那么h相同的会被覆盖掉比如数据1 1 1 1 2 2 2 2,其中一个2 2会被另一个2 2覆盖掉,导致结果为3*/ #include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct node
{
int w,h;
}p[];
int cmp(const node a,const node b)
{
if(a.w==b.w) return a.h<b.h;
return a.w>b.w;
}
int find(int *p,int len,int n)
{
int l=,r=len;
int mid=(l+r)/;
while(l<=r)
{
if(n>=p[mid]) l=mid+;
else r=mid-;
mid=(l+r)/;
}
/*while(l<=r)//最长递增子序列的二分查找
{
if(n>p[mid]) l=mid+1;
else if(n<p[mid]) r=mid-1;
else return mid;//递增不应许有两个高度一样的,所以要覆盖
mid=(l+r)/2;
}*/
return l;
}
int main()
{
int i,j,k,n,m;
int T;
int c[];
scanf("%d",&T);
while(T--)
{
memset(c,,sizeof(c));
scanf("%d",&n);
for(i=;i<n;i++)
{
scanf("%d%d",&p[i].w,&p[i].h);
}
sort(p,p+n,cmp);
int len=;
c[]=-;
c[]=p[].h;
for(i=;i<n;i++)
{
j=find(c,len,p[i].h);
c[j]=p[i].h;
if(j==len+) len++;
}
printf("%d\n",len);
}
return ;
}

Nested DollsHDU1677的更多相关文章

  1. Nested Loops join时显示no join predicate原因分析以及解决办法

    本文出处:http://www.cnblogs.com/wy123/p/6238844.html 最近遇到一个存储过程在某些特殊的情况下,效率极其低效, 至于底下到什么程度我现在都没有一个确切的数据, ...

  2. Error on line -1 of document : Premature end of file. Nested exception: Premature end of file.

    启动tomcat, 出现, ( 之前都是好好的... ) [lk ] ERROR [08-12 15:10:02] [main] org.springframework.web.context.Con ...

  3. SQL Tuning 基础概述06 - 表的关联方式:Nested Loops Join,Merge Sort Join & Hash Join

    nested loops join(嵌套循环)   驱动表返回几条结果集,被驱动表访问多少次,有驱动顺序,无须排序,无任何限制. 驱动表限制条件有索引,被驱动表连接条件有索引. hints:use_n ...

  4. [LeetCode] Nested List Weight Sum II 嵌套链表权重和之二

    Given a nested list of integers, return the sum of all integers in the list weighted by their depth. ...

  5. [LeetCode] Flatten Nested List Iterator 压平嵌套链表迭代器

    Given a nested list of integers, implement an iterator to flatten it. Each element is either an inte ...

  6. [LeetCode] Nested List Weight Sum 嵌套链表权重和

    Given a nested list of integers, return the sum of all integers in the list weighted by their depth. ...

  7. 禁用nested loop join里的spool

    禁用nested loop join里的spool 转载自: https://blogs.msdn.microsoft.com/psssql/2015/12/15/spool-operator-and ...

  8. Android Fragment使用(二) 嵌套Fragments (Nested Fragments) 的使用及常见错误

    嵌套Fragment的使用及常见错误 嵌套Fragments (Nested Fragments), 是在Fragment内部又添加Fragment. 使用时, 主要要依靠宿主Fragment的 ge ...

  9. 1122MySQL性能优化之 Nested Loop Join和Block Nested-Loop Join(BNL)

    转自http://blog.itpub.net/22664653/viewspace-1692317/ 一 介绍  相信许多开发/DBA在使用MySQL的过程中,对于MySQL处理多表关联的方式或者说 ...

随机推荐

  1. eclipse配置weblogic服务器

    最近项目要从tocmat迁移到weblogic,使用weblogic的原因不用多说,好处不言而喻.于是准备配置基于eclipse的weblogic服务器,并将整个过程记录下来分享给大家.       ...

  2. 【vijos】1770 大内密探(树形dp+计数)

    https://vijos.org/p/1770 不重不漏地设计状态才能正确的计数QAQ 虽然可能最优化是正确的,但是不能保证状态不相交就是作死.... 之前设的状态错了... 应该设 f[i][0] ...

  3. Ubuntu修改默认root及密码

    Ubuntu的默认root密码是随 机的,即每次开机都有一个新的 root密码. 我们可以在终端输入命令 sudo passwd, 然后输入当前用户的密码,enter, 终端会提示我们输入新的密码并确 ...

  4. JS encodeURI和encodeURIComponent

    一.最常用的encodeURI和encodeURIComponent 对URL编码是常见的事,所以这两个方法应该是实际中要特别注意的.它们都是编码URL,唯一区别就是编码的字符范围,其中encodeU ...

  5. push certificate

    developer_identity.cer <= download from Applemykey.p12 <= Your private key openssl x509 -in de ...

  6. python bottle学习(一)快速入门

    from bottle import (run, route, get, post, put, delete) # bottle中添加路由的两种方法 # 第一种,使用route装饰器,需要指定meth ...

  7. linux下安装oracle sqlplus以及imp、exp工具

    一.下载oracle 11g sqlplus软件 linux 64位操作系统,oracle安装包地址 http://www.oracle.com/technetwork/topics/linuxx86 ...

  8. json字符串和json对象的转换

    http://www.json.org/提供了一个json2.js,这样ie8(兼容模式),ie7和ie6就可以支持JSON对象以及其stringify()和parse()方法: parse用于从一个 ...

  9. Handlebars.js,Json+ajax+拼html

    英文版:http://handlebarsjs.com./ 原文链接:http://www.cnblogs.com/diligenceday/p/4105229.html, http://segmen ...

  10. 初识Flutter

    什么是Flutter 官网的定义如下: Flutter is a new project to help developers build high-performance, high-fidelit ...