Wooden Sticks

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 15987    Accepted Submission(s): 6564

Problem 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 (4,9), (5,2), (2,1), (3,5), and (1,4), then the minimum setup time should be 2 minutes since there is
a sequence of pairs (1,4), (3,5), (4,9), (2,1), (5,2).
 
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 n 2 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
 
Recommend
We have carefully selected several similar problems for you:  1050 1052 1045 1009 1053 


好久没写过LIS这种题了
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
using namespace std;
struct node
{
int l,w;
}s[10010];
int dp[10010];
int cmp(node s1,node s2)
{
if(s1.l<s2.l)
return 1;
else if(s1.l==s2.l)
return s1.w<s2.w;
return 0;
}
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
memset(dp,0,sizeof(dp));
for(int i=0;i<n;i++)
scanf("%d%d",&s[i].l,&s[i].w),dp[i]=1;
sort(s,s+n,cmp);
int maxx=0;
for(int i=0;i<n;i++)
{
for(int j=0;j<i;j++)
{
if(s[i].w<s[j].w&&dp[i]<dp[j]+1)
dp[i]=dp[j]+1;
}
maxx=max(maxx,dp[i]);
}
printf("%d\n",maxx);
}
return 0;
}

hdoj--1051--Wooden Sticks(LIS)的更多相关文章

  1. HDOJ.1051 Wooden Sticks (贪心)

    Wooden Sticks 点我挑战题目 题意分析 给出T组数据,每组数据有n对数,分别代表每个木棍的长度l和重量w.第一个木棍加工需要1min的准备准备时间,对于刚刚经加工过的木棍,如果接下来的木棍 ...

  2. HDOJ 1051. Wooden Sticks 贪心 结构体排序

    Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  3. HDOJ 1051. Wooden Sticks

    题目 There is a pile of n wooden sticks. The length and weight of each stick are known in advance. The ...

  4. HDU 1051 Wooden Sticks (贪心)

    Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  5. 1051 Wooden Sticks

    Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  6. HDU 1051 Wooden Sticks 贪心||DP

    Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  7. HDU - 1051 Wooden Sticks 贪心 动态规划

    Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)    ...

  8. hdu 1051:Wooden Sticks(水题,贪心)

    Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  9. 杭电 1051 Wooden Sticks

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

  10. HDU 1051 Wooden Sticks【LIS】

    题意:给出n个木头的重量wi,长度li,如果满足w[i+1]>=w[i]且l[i+1]>=l[i],则不用耗费另外的加工时间,问至少需要多长时间加工完这些木头. 第一次做这一题目也没有做出 ...

随机推荐

  1. python基本数据类型之元祖tuple

    元祖tuple 是对列表的二次加工,书写格式为括号(),里面放元素 元组的一级元素不可被修改,且不能被增加和删除 一般写元组的时候,推荐在最后加入逗号,  能加则加 创建元组 ? 1 tu = (11 ...

  2. Npgsql使用入门(一)【搭建环境】

    首先去官网下载最新数据库安装包 postgresql-9.6.1-1-windows-x64 将postgreSQL9.6注册为windows服务 注意:大小写要正确 D:\Worksoftware\ ...

  3. Git Learning Part II - Working locally

    file status life circle basic: modified:   Examples: untracked: unmodified: modified: Git branching ...

  4. 参数转对象 类似 ?camera=1&travel=0&faceScore=1

    parseQueryString(url) { var obj = {}; var keyvalue = []; var key = "", value = "" ...

  5. C# 学习笔记_类

    定义:将成员及方法封装到类中,类的实例则称为对象. 结构:属性,类修饰符,class,类名,{类体} 类修饰符:new,public,protected,internal,private,abstra ...

  6. Eclipse中添加对Python的中文支持

    原文链接:http://down.51cto.com/data/751371 首先要确保eclipse编辑器环境的编码为utf8,这个是大前提:其次如果py文件中含有中文字符的话,需要在py文件中对编 ...

  7. Java为什么需要基本类型

    提问 首先抛出问题吧:Java为什么需要基本类型? 最开始遇到这个问题的场景不记得了,但是一查之下,发现一个问题:Java既然是面向对象的,宣称一切都是对象,为什么还有基础类型. 先上结论 为了性能+ ...

  8. 自定义View(未完待续)

    一.概述 android提供了丰富的系统控件,但在实际开发中,这些控件依然不能完全覆盖我们的需求.有时,我们需要自定义控件来满足一些个性化产品需求.自定义控件,主要有以下三种方式: 继承现有控件,对其 ...

  9. node——模块化

    之前写的新闻部分几乎所有操作都写在了一起,这次开始进行模块化. 为什么要模块化: 1.提高开发效率,所有操作在一个文件内,不方便团队操作,模块化可多人同时操作 2.当程序出错,可以分模块寻找错误 3. ...

  10. Mysql5.7安装过程----win10

    ---恢复内容开始--- 1.Mysql官网:https://www.mysql.com/downloads/ 有两种下载方式:msi和zip压缩包 2.我下载的是zip压缩包,选择mysql com ...