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. Tomcat 日志切割

    一.installing 日志轮训工具 yum  install cronolog -y 二.安装.修改tomcat文件 wget  http://mirrors.shuosc.org/apache/ ...

  2. BZOJ1060: [ZJOI2007]时态同步(树形dp 贪心)

    Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 3285  Solved: 1286[Submit][Status][Discuss] Descript ...

  3. SQL数据库链接代码的解释

    SqlConnection conn = new SqlConnection(); conn.ConnectionString = "Data Source=(local);Initial ...

  4. 解决启动httpd报: apr_sockaddr_info_get() failed for错误

    我测试库里 service httpd start 时报 下面错误 httpd: apr_sockaddr_info_get() failed for fengxin.wzjzt.centoshttp ...

  5. 异常及String

    异常时描述错误信息的对象,在编码过程中我们会遇到很多异常 例如: 1.java.lang.ArithmeticException 算数异常.算数运算出现错误时抛出 比如用0做除数 2.java.lan ...

  6. profibus

    在研究profibus之前先提出问题,带着问题查看 profibus跟硬件无关?只是软件上的协议复杂? profibus和modbus的区别? 解读: profibus跟硬件关系不大,profibus ...

  7. OpenSessionInViewFilter浅谈

    本篇文章转载自--OpenSessionInViewFilter的配置及作用 spring为我们解决hibernate的Session的关闭与开启问题. Hibernate 允许对关联对象.属性进行延 ...

  8. 跳出语句 break continue

    break 使用场景:终止switch或者循环 在选择结构switch语句中 在循环语句中 离开使用场景的存在是没有意义的 public static void main(String[] args) ...

  9. vc++如何创建程序01

    1 .选择文件+新建(ctrl+N),然后选择一个空的工程,完成 2 然后在选择file新建,在files文件下面选择一个C++Source File,并取个文件名(比如为point可以不带.c) 我 ...

  10. cent os 安装mariaDB / mySQL 之后初始化的命令

      #安装mysql mysql-server,默认安装的是开源的mariaDB和它的server,mariadb-server,安装源中可能有找不到的,就换个名字再找找 yum install -y ...