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. Delphi定时器控件TTimer“一睡不醒”问题研究

    1,试验1—基础代码 1.1页面控件与代码 定时器 Timer1 Timer_work Interval 1000 1500 Enabled True True Ontimer事件 then exit ...

  2. 洛谷 P3038 [USACO11DEC]牧草种植Grass Planting

    题目描述 Farmer John has N barren pastures (2 <= N <= 100,000) connected by N-1 bidirectional road ...

  3. 洛谷 P1910 L国的战斗之间谍(水题日常)

    题目背景 L国即将与I国发动战争!! 题目描述 俗话说的好:“知己知彼,百战不殆”.L国的指挥官想派出间谍前往I国,于是,选人工作就落到了你身上. 你现在有N个人选,每个人都有这样一些数据:A(能得到 ...

  4. Tomcat和搜索引擎网络爬虫的攻防

    不知道广大程序员朋友们注意到一个现象么?使用百度是无法搜索到淘宝网的网页.为什么会造成这种现象?这就要从网络爬虫说起了. 咱们程序员假如自己搭设个人网站,在上面分享少量自己的技术文章,面临的一个重要问 ...

  5. Qt setWindow setViewPort

    painter.setWindow(-50, -50, 100, 100); //表示x,y坐标不变,可视的窗口移动到(-50,-50)的位置.同时在x,y方向产生factorx= (window.w ...

  6. G7或变G6+1?特朗普七国峰会箱友军开炮

    今日导读 G7 峰会刚召开完毕,德国总理默克尔发的一张照片就迅速火遍全球.照片中她身体前倾,像是在质问特朗普,而后者则双手交叉胸前,我自岿然不动,这张火药味十足的照片不禁让人脑补当时剑拔弩张的气氛.到 ...

  7. Android Studio集成crashlytics后无法编译的问题

    http://blog.csdn.net/zhuobattle/article/details/50555393 问题描述: 在用fabric集成后编译出现如下错误, Error:Cause: hos ...

  8. CPP-STL:随机数发生器random_shuffle

    //--------------------------------------------------------------------------- #include <string.h& ...

  9. JSP页面通过c:forEach标签循环遍历List集合

    c:forEach>标签有如下属性: 属性 描述 是否必要 默认值items 要被循环的信息 否 无begin 开始的元素(0=第一个元素,1=第二个元素) 否 0end 最后一个元素(0=第一 ...

  10. android开发链接

    http://blog.csdn.net/zz2043191420/article/details/47338591