Wooden Sticks---hdu1051(最长上升子序列)
http://acm.hdu.edu.cn/showproblem.php?pid=1051
(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).
#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(最长上升子序列)的更多相关文章
- Wooden Sticks(hdu1051)
Wooden Sticks Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submi ...
- POJ-1065 Wooden Sticks,排序+最长单减子序列!
Wooden Sticks 题意:有一台机器处理木材,最开始需要一分钟准备,如果后面处理的木材比前 ...
- SPOJ 3937 - Wooden Sticks 最长上升子序列LIS
给了n个(n<=5000)木棍的长度hi与宽度wi(均小于10000),现在机器要打磨这些木棍,如果相邻连个木棍hi<=hj并且wi<=wj就不需要调整机器,问如何排序使得机器调整的 ...
- POJ - 1065 Wooden Sticks(贪心+dp+最长递减子序列+Dilworth定理)
题意:给定n个木棍的l和w,第一个木棍需要1min安装时间,若木棍(l’,w’)满足l' >= l, w' >= w,则不需要花费额外的安装时间,否则需要花费1min安装时间,求安装n个木 ...
- HDU-1051/POJ-1065 Wooden sticks 木棍子(动态规划 LIS 线型动归)
嘤嘤嘤,实习半年多的小蒟蒻的第一篇博客(题解) 英文的: There is a pile of n wooden sticks. The length and weight of each stick ...
- HDU1051 Wooden Sticks 【贪婪】
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- 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 ...
- hdu1051 Wooden Sticks(贪心+排序,逻辑)
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- HDU1051:Wooden Sticks
Problem Description There is a pile of n wooden sticks. The length and weight of each stick are know ...
随机推荐
- sql通过 openrowset查询csv文件
两步即可完成 第一步. 创建cmmData.xml文件,并存入到能与sql服务器共享的文件夹中(如:\\10.252.21.6\sharedfolder) <?xml version=" ...
- ubuntu破解密码方法
摘要: 开机按住任何键(shift)停住grub菜单,进入advanced option for ubuntu,出现的菜单中,光标移动至…(recovery mode)按E进入编辑,找到ro reco ...
- Android(java)学习笔记167:横竖屏切换时Activity的生命周期
1.横竖屏切换的生命周期 默认情况下横竖屏切换,先销毁再创建 2.有的时候,默认情况下的横竖屏切换(先销毁再创建),对应用户体验是不好的,比如是手机游戏横竖屏切换对游戏体验非常不好,下面两种方 ...
- swift Equatable 的缺省实现
Starting from Swift 4.1, all you have to is to conform to the Equatable protocol without the need of ...
- DoveCLL and Resistance(湖北省赛)
题目 构造一个由串联和并联构成的纯电阻电路,使得该电路的等效电阻为p/q,其中(p,q) = 1.要求输出n,表示节点数,m表示电阻个数,m行每行ui,vi,wi,表示ui和vi之间要连上一个电阻为w ...
- dockerfile 的最佳实践
Dockerfile 编写nginx容器 [root@mast nginx]# cat Dockerfile FROM centos MAINTAINER zhaoruidong RUN yum -y ...
- C++静态全局变量和全局变量的区别
静态全局变量 非静态全局变量 存储方式 静态存储 静态存储 作用域 定义该变量的源文件内 所有源文件 解释: 共同点:全局变量(外部变量)的说明之前再冠以static 就构 成了静态的全局变量.全 ...
- 【软件构造】第三章第四节 面向对象编程OOP
第三章第四节 面向对象编程OOP 本节讲学习ADT的具体实现技术:OOP Outline OOP的基本概念 对象 类 接口 抽象类 OOP的不同特征 封装 继承与重写(override) 多态与重载( ...
- JavaEE-07 过滤器和监听器
学习要点 过滤器 监听器 过滤器Filter 过滤器的概念 过滤器位于客户端和web应用程序之间,用于检查和修改两者之间流过的请求和响应. 在请求到达Servlet/JSP之前,过滤器截获请求. 在响 ...
- dockerfile note
dockerfile note reference summary defination docker can build images automatically by reading the in ...