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. 改进"尽最大努力交付"的服务

    改进"尽最大努力交付"的服务 网络层的作用就是负责在不同的网段尽力转发数据包,但是负责中专数据包的路由器并不关心数据包的内容和优先顺序.而是先到达的数据包先处理,后到达的数据包排队 ...

  2. Pycharm2019.2激活至2089年

    PyCharm作为日常开发常用工具,过段时间就需要再次激活是个问题,今早找到个方法很实用,亲测也是有效的.激活成功如下图: 具体步骤如下: 1. 下载破解补丁和激活码[小哈学Java公众号提供],使用 ...

  3. flask-restful 初探

    flask-restful 是 Flask 的一个用于支持 RESTful 的插件. 刚开始用对我来说还是比较坑的... 目录结构 / /test /test/common /__init__.py ...

  4. vmware企业虚拟化平台vSphere管理与配置

    ├─1-CCIE-DC课程介绍.avi ├─2-vSphere-简介.avi ├─3-vSphere-新功能介绍.avi ├─4-vSphere-授权介绍.avi ├─5-vSphere-课程拓扑介绍 ...

  5. url,href和src的区别,defer和async的区别

    URL(Uniform Resource Locator):统一资源定位符,互联网上的每个文件都有一个唯一的URL,基本URL包含协议,IP地址,路径和文件名. 重点:herf和src的区别 href ...

  6. vuex的使用心得

    今天的工作内容-----vuex的使用心得: 都知道,对于小型的项目来说不必使用vuex,但是对于需要把共享的变量全部存储在一个对象里面,然后把这个对象放在顶层组件中以供其他组件使用.其实vuex就是 ...

  7. java编写非对称加密,解密,公钥加密,私钥解密,RSA,rsa

    非对称加密已经被评为加密标准,主要包含(公钥加密私钥解密,或者私钥加密公钥解密)本文主要讲解的是如何用java生成 公钥和私钥并且 进行字符串加密 和字符串解密    //如需要代码copy如下 im ...

  8. DOM是什么(初级版)

    js新手村出村之路--基础知识 在这里默认你已经粗粗的自学过了一遍js知识.(也许是在昏昏欲睡的课堂上听了两分钟,也许是跟着b站上的视频打了一遍.who cares) 在下面的内容中我将整理一些在平常 ...

  9. wentiqingdan

    1. Python不用在行尾加分号,也不要用分号将两条命令放在同一行,但加上分号也能执行,不像C/C++分号是必须加的,缺了就会出错. 2. C属于编译型语言,Python属解型语言 编译型的优点是& ...

  10. 聊聊order by的工作机制

    总结写在前面: 1. 介绍了orderBy的两种算法流程:全字段排序 和 rowid排序. 2. rowid排序 相比 全字段排序,参与排序字段较少,耗内存较少,多一步回表,如果内存够的情况下MySQ ...