HDU-1051 一个DP问题
Problem Description
(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
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
分析
这道题是问将一组木条划分一下,要求每个链中长度和重量是不下降的,求最少能分出几个链,好像挺眼熟的感觉?没错这不是导弹拦截吗?如果你对迪尔沃斯(音译)定理了解足够深的话,接下来怎么做就很明了了,最少链的划分=最长反链的长度,数据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问题的更多相关文章
- HDU 2836 (离散化DP+区间优化)
Reference:http://www.cnblogs.com/wuyiqi/archive/2012/03/28/2420916.html 题目链接: http://acm.hdu.edu.cn/ ...
- HDU 3392 Pie(DP)
题意:有一些男生女生,男生女生数量差不超过100 ,男生女生两两配对.要求求出一种配对方法,使每一对的高度差的和最小. 思路:(我是真的笨笨笨!!)设人少的一组人数为n,b[],人多的一组人数为m,g ...
- hdu 4507 数位dp(求和,求平方和)
http://acm.hdu.edu.cn/showproblem.php?pid=4507 Problem Description 单身! 依旧单身! 吉哥依旧单身! DS级码农吉哥依旧单身! 所以 ...
- hdu 3709 数字dp(小思)
http://acm.hdu.edu.cn/showproblem.php?pid=3709 Problem Description A balanced number is a non-negati ...
- hdu 4283 区间dp
You Are the One Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- HDU 2829 区间DP & 前缀和优化 & 四边形不等式优化
HDU 2829 区间DP & 前缀和优化 & 四边形不等式优化 n个节点n-1条线性边,炸掉M条边也就是分为m+1个区间 问你各个区间的总策略值最少的炸法 就题目本身而言,中规中矩的 ...
- HDOJ(HDU).2159 FATE (DP 带个数限制的完全背包)
HDOJ(HDU).2159 FATE (DP 带个数限制的完全背包) 题意分析 与普通的完全背包大同小异,区别就在于多了一个个数限制,那么在普通的完全背包的基础上,增加一维,表示个数.同时for循环 ...
- [hdu 1398]简单dp
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1398 看到网上的题解都是说母函数……为什么我觉得就是一个dp就好了,dp[i][j]表示只用前i种硬币 ...
- B - Lawrence HDU - 2829 斜率dp dp转移方程不好写
B - Lawrence HDU - 2829 这个题目我觉得很难,难在这个dp方程不会写. 看了网上的题解,看了很久才理解这个dp转移方程 dp[i][j] 表示前面1~j 位并且以 j 结尾分成了 ...
- HDU 3853(期望DP)
题意: 在一个r*c的网格中行走,在每个点分别有概率向右.向下或停止不动.每一步需要的时间为2,问从左上角走到右下角的期望时间. SOL: 非常水一个DP...(先贴个代码挖个坑 code: /*== ...
随机推荐
- Spring-cloud微服务实战【十】:消息总线Bus
回忆一下,在上一篇文章中,我们使用了分布式配置中心config来管理所有微服务的配置文件,那这样有没有什么问题?有,那就是无法配置文件无法自动更新,当我的git服务器上的配置文件更新后,不能同步更 ...
- Intellij IDEA 干货分享
更多视频详情:https://www.bilibili.com/video/av89385013/ Intellij IDEA 真是越用越强大 它总是在我们写代码的时候 不时给我们来个小惊喜 出于对 ...
- 简单的员工管理系统(Mysql+jdbc+Servlet+JSP)
员工管理系统 因为学业要求,需要完成一个过关检测,但是因为检测之前没有做好准备,且想到之前用mysql+jdbc+Struts2+bootstrap做成了一个ATM系统(主要有对数据的增删改查操作), ...
- Ribbon进行服务调用/负载均衡以及请求重试配置
Ribbon负载均衡 经过对Eureka的认识,及Eureka集群的搭建,已经基本可以入门Eureka的使用.之前对于服务调用者我们是直接获取注册列表后通过 get(0) 的方式来获取第一个注册信息. ...
- 7-45 jmu-python-涨工资 (10 分)
输入一组工资数据,写入列表.对于小于5000的工资,涨1.5倍.并输出涨后的工资数据. 输入格式: 数据之间空格隔开 输出格式: 涨工资后的数据,空格隔开.尾部 不带空格. 输入样例: 3000 40 ...
- UBB代码
UBB代码是HTML(标准通用标记语言下的一个应用)的一个变种,是Ultimate Bulletin Board (国外的一个BBS程序)采用的一种特殊的TAG.您也许已经对它很熟悉了.UBB代码很简 ...
- css实战#用css画一个中国结
大家好!今天跟大家分享一个用 css 画中国结的教程.最终效果如下: 大家如果感兴趣可以参考我的源码:gitHub地址 首先,我们定义好画中国结需要的结构: <div class="k ...
- 浏览器渲染流程&Composite(渲染层合并)简单总结
梳理浏览器渲染流程 首先简单了解一下浏览器请求.加载.渲染一个页面的大致过程: DNS 查询 TCP 连接 HTTP 请求即响应 服务器响应 客户端渲染 这里主要将客户端渲染展开梳理一下,从浏览器器内 ...
- 小白的springboot之路(十六)、mybatis-plus 的使用
0-前言 mybatis plus是对mybatis的增强,集成mybatis plus后,简单的CRUD和分页就不用写了,非常方便,五星推荐: 1-集成 1-1.添加依赖 <!-- .集成my ...
- XCTF---easyjava的WriteUp
一.题目来源 题目来源:XCTF题库安卓区easyjava 题目下载链接:下载地址 二.解题过程 1.将该apk安装进夜神模拟器中,发现有一个输入框和一个按钮,随便输入信息,点 ...