Wooden Sticks
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 21902   Accepted: 9353

Description

There is a pile of n wooden sticks. The length and weight of each stick are known in advance. The sticks are to be processed by a woodworking machine in one by one fashion. It needs some time, called setup time, for the machine to prepare processing a stick. The setup times are associated with cleaning operations and changing tools and shapes in the machine. The setup times of the woodworking machine are given as follows: 
(a) The setup time for the first wooden stick is 1 minute. 
(b) Right after processing a stick of length l and weight w , the machine will need no setup time for a stick of length l' and weight w' if l <= l' and w <= w'. Otherwise, it will need 1 minute for setup. 
You are to find the minimum setup time to process a given pile of n wooden sticks. For example, if you have five sticks whose pairs of length and weight are ( 9 , 4 ) , ( 2 , 5 ) , ( 1 , 2 ) , ( 5 , 3 ) , and ( 4 , 1 ) , then the minimum setup time should be 2 minutes since there is a sequence of pairs ( 4 , 1 ) , ( 5 , 3 ) , ( 9 , 4 ) , ( 1 , 2 ) , ( 2 , 5 ) . 

Input

The input consists of T test cases. The number of test cases (T) is given in the first line of the input file. Each test case consists of two lines: The first line has an integer n , 1 <= n <= 5000 , that represents the number of wooden sticks in the test case, and the second line contains 2n positive integers l1 , w1 , l2 , w2 ,..., ln , wn , each of magnitude at most 10000 , where li and wi are the length and weight of the i th wooden stick, respectively. The 2n integers are delimited by one or more spaces. 

Output

The output should contain the minimum setup time in minutes, one per line. 

Sample Input

3
5
4 9 5 2 2 1 3 5 1 4
3
2 2 1 1 2 2
3
1 3 2 2 3 1

Sample Output

2
1
3

Source

--------------------------
和poj3636同样的道理
因为偏序关系是<=,所以w从小到大相同l小的在前,找最长下降子序列
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int N=,INF=1e9;
struct data{
int w,l;
}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.l<b.l?:;
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].l;
for(int i=;i<=n;i++){
int k=lower_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].l,&da[i].w);
printf("%d\n",dp());
}
return ;
}

POJ1065Wooden Sticks[DP LIS]的更多相关文章

  1. poj1065Wooden Sticks(dp——最长递减数列)

    Description There is a pile of n wooden sticks. The length and weight of each stick are known in adv ...

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

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

  3. 拦截导弹类问题 (Codevs4888零件分组POJ1065Wooden Sticks)(LIS及其覆盖问题)

    拦截导弹 题意:求最长不上升子序列长度:求一个序列最少分成几个非增子序. 第一问易求,已知序列a,令f[i]为a前i个元素的最长非增子序的长度,则有 f[i]=max{f[i],f[j]+1} (1& ...

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

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

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

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

  6. 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 ...

  7. 2015南阳CCPC D - Pick The Sticks dp

    D - Pick The Sticks Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 无 Description The story happened lon ...

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

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

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

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

随机推荐

  1. 连接QuickBooks Online实现于IOS App数据同步功能的个人记录

    公司项目需要用WebService与QBO实现后台数据同步,由于国内没有做过类似第三方产品接口的资料,前前后后找了N久,终于实现功能,现把实现功能步骤贴上来分享: QBO开发者地址(主要用于创建QBO ...

  2. JSOM 对User的操作

    一.操作当前用户 //Load current user info function LoadCurUser() { var curUser; curUser = curWeb.get_current ...

  3. 【IOS】从android角度来实现(理解)IOS的UITableView

    以下内容为原创,欢迎转载,转载请注明 来自天天博客:http://www.cnblogs.com/tiantianbyconan/p/3403124.html   本人从在学校开始到现在上班(13年毕 ...

  4. LBS上传到百度地图

    准备: 第一步:注册百度地图开发者账号 第二步:使用开发者账号注册相对应秘钥 在LBS后台添加所需要上传的字段 1,添加WebClientHelper帮助类 2,LBS帮助类 private stri ...

  5. JS DOM学习笔记

    1.window对象代表当前浏览器窗口 2.使用window对象的属性.方法的时候可以省略window.例如:window.alert("hello")一般写成alert(&quo ...

  6. objective-c系列-NSString

    C中没有字符串变量的概念 只有一个字符串常量的概念 即:   “abcd” 在c中,用一个字符串指来指向一个内存地址, 然后从该地址往后,遇到'\0'结束,这一段 内存就表述为一个字符串 char * ...

  7. 【读书笔记】iOS网络-Cookie

    Cookie是HTTP协议在首个版本之后加入的一个重要组件.它向服务器提供了追踪会话状态的能力,同时又无须维持客户端与服务器之间的连接.在浏览器客户端,Cookie值是由服务器通过请求提供的,,然后被 ...

  8. css简介及相关概念

    一.简介: css全称为级联样式表(Cascading Style Sheet),通常又称为风格样式表(Style Sheet),是用来进行网页风格设计的.  css优点: 内容与表现分离 表现的统一 ...

  9. 转:无法向会话状态服务器发出会话状态请求请。确保 ASP.NET State Service (ASP.NET 状态服务)已启动

    今天看到一篇文章感觉不错,收藏转载下. 原文地址:http://blog.csdn.net/sntyy/article/details/2090347 版权为原作者所有 无法向会话状态服务器发出会话状 ...

  10. 后台管理UI皮肤的选择

    后台管理UI的选择 目录 一.EasyUI 二.DWZ JUI 三.HUI 四.BUI 五.Ace Admin 六.Metronic 七.H+ UI 八.Admin LTE 九.INSPINIA 十. ...