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.

分析

  这道题是问将一组木条划分一下,要求每个链中长度和重量是不下降的,求最少能分出几个链,好像挺眼熟的感觉?没错这不是导弹拦截吗?如果你对迪尔沃斯(音译)定理了解足够深的话,接下来怎么做就很明了了,最少链的划分=最长反链的长度,数据n<=5000,n2就可以不需要加优化。

  如果你很好奇定理证明,自行百度……

  

 #include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=1e5+;
int dp[N];
struct Node{
int l,w;
bool operator <(const Node &A)const{
if(l==A.l){
if(w==A.w)return ;
return w<A.w;
}
return l<A.l;
}
}a[N];
int main(){
int t;
cin>>t;
while(t--){
int n;
memset(dp,,sizeof(dp));
cin>>n;
for(int i=;i<=n;i++){
cin>>a[i].l>>a[i].w;
}
sort(a+,a+n+);
int ans=;
for(int i=;i<=n;i++){
dp[i]=;
for(int j=;j<i;j++)
if(a[j].w>a[i].w)
dp[i]=max(dp[j]+,dp[i]);
ans=max(dp[i],ans);
}
cout<<ans<<endl;
}
}

HDU-1051 一个DP问题的更多相关文章

  1. HDU 2836 (离散化DP+区间优化)

    Reference:http://www.cnblogs.com/wuyiqi/archive/2012/03/28/2420916.html 题目链接: http://acm.hdu.edu.cn/ ...

  2. HDU 3392 Pie(DP)

    题意:有一些男生女生,男生女生数量差不超过100 ,男生女生两两配对.要求求出一种配对方法,使每一对的高度差的和最小. 思路:(我是真的笨笨笨!!)设人少的一组人数为n,b[],人多的一组人数为m,g ...

  3. hdu 4507 数位dp(求和,求平方和)

    http://acm.hdu.edu.cn/showproblem.php?pid=4507 Problem Description 单身! 依旧单身! 吉哥依旧单身! DS级码农吉哥依旧单身! 所以 ...

  4. hdu 3709 数字dp(小思)

    http://acm.hdu.edu.cn/showproblem.php?pid=3709 Problem Description A balanced number is a non-negati ...

  5. hdu 4283 区间dp

    You Are the One Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  6. HDU 2829 区间DP & 前缀和优化 & 四边形不等式优化

    HDU 2829 区间DP & 前缀和优化 & 四边形不等式优化 n个节点n-1条线性边,炸掉M条边也就是分为m+1个区间 问你各个区间的总策略值最少的炸法 就题目本身而言,中规中矩的 ...

  7. HDOJ(HDU).2159 FATE (DP 带个数限制的完全背包)

    HDOJ(HDU).2159 FATE (DP 带个数限制的完全背包) 题意分析 与普通的完全背包大同小异,区别就在于多了一个个数限制,那么在普通的完全背包的基础上,增加一维,表示个数.同时for循环 ...

  8. [hdu 1398]简单dp

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1398 看到网上的题解都是说母函数……为什么我觉得就是一个dp就好了,dp[i][j]表示只用前i种硬币 ...

  9. B - Lawrence HDU - 2829 斜率dp dp转移方程不好写

    B - Lawrence HDU - 2829 这个题目我觉得很难,难在这个dp方程不会写. 看了网上的题解,看了很久才理解这个dp转移方程 dp[i][j] 表示前面1~j 位并且以 j 结尾分成了 ...

  10. HDU 3853(期望DP)

    题意: 在一个r*c的网格中行走,在每个点分别有概率向右.向下或停止不动.每一步需要的时间为2,问从左上角走到右下角的期望时间. SOL: 非常水一个DP...(先贴个代码挖个坑 code: /*== ...

随机推荐

  1. USB小白学习之路(8)FX2LP cy7c68013A——Slave FIFO 与FPGA通信(转)

    此博客转自CSDN:http://blog.csdn.net/xx116213/article/details/50535682 这个博客只对自己理解CY7C68013的配置有一定的帮助,对于配置CY ...

  2. USB小白学习之路(3) 通过自定义请求存取外部RAM

    通过自定义请求存取外部RAM 1. 实验简述 此实验是对自定义的供应商特殊命令(vendor specific command bRequest = 0xA3)进行解析,程序中的read me说明如下 ...

  3. nvm安装以及注意事项

    nvm初衷:由于以后的开发工作可能会在多个Node版本中测试,而且Node的版本也比较多,所以需要这么款工具来管理 1. 下载:[nvm-windows](https://github.com/cor ...

  4. 从头认识js-js中的对象

    什么是对象? ECMA-262中把对象定义为:“无序属性的集合,其属性可以包含基本值,对象或者函数”.严格来讲,对象是一组没有特定顺序的值.对象的每个属性或方法·都有一个名字,而每个名字都映射到一个值 ...

  5. DIV的失去焦点(blur)实现

    用防抖实现DIV鼠标移出消失   由于div标签本身不支持onblur事件,所以对于点击一个按钮弹出的div,我们想要当这个div失去焦点的时候,让它消失不能使用的onblur来实现.  但是可以利用 ...

  6. Spring Boot 2.x基础教程:使用MyBatis的XML配置方式

    上一篇我们介绍了如何在Spring Boot中整合我们国人最常用的MyBatis来实现对关系型数据库的访问.但是上一篇中使用了注解方式来实现,而对于很多MyBatis老用户还是习惯于XML的开发方式, ...

  7. linux最常用命令记录(一)

    一.vim个人最常用设置: vim .vimrc 然后添加以下内容 set nu set tabstop=4 set encoding=utf-8 二.查看磁盘空间相关命令 1.df -h   查看硬 ...

  8. 关于form表单:hover没有修改表单子元素样式

    原来在写todolist的时候遇到的一个问题 是关于form表单的hover属性设置背景颜色 想要实现的效果如下: 但是一开始直接给form加hover选择器的时候是这样: 可以看到这样子直接加会使得 ...

  9. Rust入坑指南:齐头并进(上)

    我们知道,如今CPU的计算能力已经非常强大,其速度比内存要高出许多个数量级.为了充分利用CPU资源,多数编程语言都提供了并发编程的能力,Rust也不例外. 聊到并发,就离不开多进程和多线程这两个概念. ...

  10. XSS(跨站脚本攻击)详解

    跨站脚本攻击XSS(Cross Site Scripting),为了不和层叠样式表(Cascading Style Sheets, CSS)的缩写混淆,故将跨站脚本攻击缩写为XSS.恶意攻击者往Web ...