http://acm.hdu.edu.cn/showproblem.php?pid=1051

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
这道题刚开始并不知道怎么写   丝毫没有思路  后来发现这不就是上升子序列么
但是还是忘了怎么写   就翻了之前的博客有调试一下才看懂
发现真是学的不快忘得挺快   唉  
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<queue> using namespace std; #define N 5500
struct node
{
int u,v;
}a[N]; int cmp(const void *x,const void *y)
{
struct node *c,*d;
c=(struct node *)x;
d=(struct node *)y;
if(c->u!=d->u)
return d->u-c->u;
else
return d->v-c->v;
}
int main()
{
int T,n;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(int i=;i<n;i++)
{
scanf("%d %d",&a[i].u,&a[i].v);
}
qsort(a,n,sizeof(a[]),cmp);
int dp[N];
int Max=;
for(int i=;i<n;i++)
{
dp[i]=;
for(int j=;j<i;j++)
{
if(a[i].v>a[j].v && dp[j]+>dp[i])
dp[i]=dp[j]+;
}
if(dp[i]>dp[Max])
Max=i;
}
printf("%d\n",dp[Max]);
}
return ;
}

Wooden Sticks---hdu1051(最长上升子序列)的更多相关文章

  1. Wooden Sticks(hdu1051)

    Wooden Sticks Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submi ...

  2. POJ-1065 Wooden Sticks,排序+最长单减子序列!

                                                       Wooden Sticks 题意:有一台机器处理木材,最开始需要一分钟准备,如果后面处理的木材比前 ...

  3. SPOJ 3937 - Wooden Sticks 最长上升子序列LIS

    给了n个(n<=5000)木棍的长度hi与宽度wi(均小于10000),现在机器要打磨这些木棍,如果相邻连个木棍hi<=hj并且wi<=wj就不需要调整机器,问如何排序使得机器调整的 ...

  4. POJ - 1065 Wooden Sticks(贪心+dp+最长递减子序列+Dilworth定理)

    题意:给定n个木棍的l和w,第一个木棍需要1min安装时间,若木棍(l’,w’)满足l' >= l, w' >= w,则不需要花费额外的安装时间,否则需要花费1min安装时间,求安装n个木 ...

  5. HDU-1051/POJ-1065 Wooden sticks 木棍子(动态规划 LIS 线型动归)

    嘤嘤嘤,实习半年多的小蒟蒻的第一篇博客(题解) 英文的: There is a pile of n wooden sticks. The length and weight of each stick ...

  6. HDU1051 Wooden Sticks 【贪婪】

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

  7. Hdu1051 Wooden Sticks 2017-03-11 23:30 62人阅读 评论(0) 收藏

    Wooden Sticks Problem Description There is a pile of n wooden sticks. The length and weight of each ...

  8. hdu1051 Wooden Sticks(贪心+排序,逻辑)

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

  9. HDU1051:Wooden Sticks

    Problem Description There is a pile of n wooden sticks. The length and weight of each stick are know ...

随机推荐

  1. Can't locate ExtUtils/MakeMaker.pm in @INC

    Can't locate ExtUtils/MakeMaker.pm in @INC 解决办法:yum install perl-devel

  2. Linux系统下查找文件的方法

    Linux系统下查找文件的方法 作者:Vashon 时间:20150419 方法一.在当前目录里查找所有名为以 java 开头的文件: find ./ -name "java*" ...

  3. redis集群架构(含面试题解析)

    老规矩,我还是以循序渐进的方式来讲,我一共经历过三套集群架构的演进! Replication+Sentinel 这套架构使用的是社区版本推出的原生高可用解决方案,其架构图如下! 这里Sentinel的 ...

  4. iOS猜拳游戏源码

    利用核心动画和Quartz2D做的一个小游戏.逻辑十分简单. 源码下载:http://code.662p.com/<ignore_js_op> 详细说明:http://ios.662p.c ...

  5. CPP-基础:模板

    // template.cpp : 定义控制台应用程序的入口点. #include "stdafx.h" #include <iostream> #include &l ...

  6. QT+ 状态栏+核心控件+浮动窗口

    #include "mainwindow.h" #include <QStatusBar> #include <QLabel> #include<QT ...

  7. Springboot 图标更换

    1.将自己的logo图片转为.ico格式的,命名必须为[favicon.ico] 2.将该图片直接放在src/main/resourecs目录下 3.重启项目,刷新一下浏览器缓存,就会发现图标更换了

  8. Ubuntu下压缩与解压各种文件的命令

    1.压缩与解压xz文件 (1)压缩 xz -z  filename (2)解压 xz -d  filename.xz 2.压缩与解压tar文件 (1)压缩 tar -cvf  filename(压缩到 ...

  9. Python之队列

    Python之队列 队列:先进先出 队列与线程有关. 在多线程编程时,会起到作用. 作用:确保信息安全的进行交换. 有get 和 put 方法. ''' 创建一个“队列”对象 import Queue ...

  10. Linux 基本操作指南

    Linux基本操作 1. su  切换用户   2.exit 退出当前登录用户 3.useradd 用户名  -m  在home目录下 创建一个和用户名同名的目录,并添加一个用户 (有root权限才能 ...