POJ1065Wooden Sticks[DP LIS]
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 21902 | Accepted: 9353 |
Description
(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
Output
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
#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]的更多相关文章
- poj1065Wooden Sticks(dp——最长递减数列)
Description There is a pile of n wooden sticks. The length and weight of each stick are known in adv ...
- hdu----(1677)Nested Dolls(DP/LIS(二维))
Nested Dolls Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- 拦截导弹类问题 (Codevs4888零件分组POJ1065Wooden Sticks)(LIS及其覆盖问题)
拦截导弹 题意:求最长不上升子序列长度:求一个序列最少分成几个非增子序. 第一问易求,已知序列a,令f[i]为a前i个元素的最长非增子序的长度,则有 f[i]=max{f[i],f[j]+1} (1& ...
- 洛谷P1108 低价购买[DP | LIS方案数]
题目描述 “低价购买”这条建议是在奶牛股票市场取得成功的一半规则.要想被认为是伟大的投资者,你必须遵循以下的问题建议:“低价购买:再低价购买”.每次你购买一支股票,你必须用低于你上次购买它的价格购买它 ...
- hdu----(1257)最少拦截系统(dp/LIS)
最少拦截系统 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- 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 ...
- 2015南阳CCPC D - Pick The Sticks dp
D - Pick The Sticks Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 无 Description The story happened lon ...
- hdu 4352 "XHXJ's LIS"(数位DP+状压DP+LIS)
传送门 参考博文: [1]:http://www.voidcn.com/article/p-ehojgauy-ot.html 题解: 将数字num字符串化: 求[L,R]区间最长上升子序列长度为 K ...
- BZOJ.1109.[POI2007]堆积木Klo(DP LIS)
BZOJ 二维\(DP\)显然.尝试换成一维,令\(f[i]\)表示,强制把\(i\)放到\(a_i\)位置去,现在能匹配的最多数目. 那么\(f[i]=\max\{f[j]\}+1\),其中\(j& ...
随机推荐
- (转)JavaScript一:为什么学习JavaScript?
Web程序不论是B/S(Browser/Server)还是C/S(Client/Server)架构,分为客户端程序与服务器端程序两种.ASP.NET是开发服务器端程序的强大工具,但是有时候为了降低服务 ...
- [原创]html5游戏_贪吃蛇
代码随便写写,尚有许多不足,PC与手机端皆可运行 手机端滑屏操作,PC端方向键操作 疑问: 生成食物,与判断是否可以移动方面 有两种实现方式, 1.使用js内存,数组循环判断 2.使用dom的quer ...
- SAP/SD - 做SD你要知道的透明表
一.客户主数据基本数据放在KNA1里:公司代码放在KNB1里:销售视图放在KNVV里:合作伙伴放在KNVP里:二.信用主数据KNKK里有信贷限额.应收总额.特别往来:S066里是未清订单值:S067里 ...
- SharePoint 向多行文本类型字段插入特殊类型链接
1.在测试列表中插入一个多行文本字段,名字叫做Content,如下图: 2.在Content字段里,添加一个Link,如下图: 3.尝试输入Notes格式的Link,如下图: 4.点击OK的时候,弹出 ...
- Spring Session
开工开工, 准备条件: 1. 本地Redis,官网:http://redis.io/,windows下 https://github.com/ServiceStack/redis-windows ht ...
- 用typedef自定义类型语法你真的会吗
关于typedef 我们学习typedef的时候,他的定义语法是:typedef+类型+别名,但是按照上面的格式,自定义数组怎么定义呢,是这样tepedef int a[10] 别名?还是这样tep ...
- 代码创建storyboard
代码创建storyboard方式如下 // 加载storyboard UIStoryboard *storyboard = [UIStoryboard StoryboardWithName:@&quo ...
- (20160601)开源第三方学习之SVProgressHUD
SVProgressHUD相信在很多项目中都有运用,运用于弹出窗提示效果: 地址:https://github.com/SVProgressHUD/SVProgressHUD 一:插件的运用 1.1 ...
- Web性能--TCP的构成
前言:阅读<Web性能权威指南>摘录笔记.在这本书开篇就读到第一句话令人印象深刻: "合格的开发者知道怎么做,而优秀的开发者知道为什么那么做". 内容大纲: 1.因特网 ...
- 个人作业week-1-14061195
软件: 根据维基百科, The first theory about software—prior to creation of computers as we know them today—was ...