HDU 1160 DP最长子序列
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Description
Input
The data for a particular mouse will consist of a pair of
integers: the first representing its size in grams and the second
representing its speed in centimeters per second. Both integers are
between 1 and 10000. The data in each test case will contain information
for at most 1000 mice.
Two mice may have the same weight, the same speed, or even the same weight and speed.
Output
should contain a number n; the remaining n lines should each contain a
single positive integer (each one representing a mouse). If these n
integers are m[1], m[2],..., m[n] then it must be the case that
W[m[1]] < W[m[2]] < ... < W[m[n]]
and
S[m[1]] > S[m[2]] > ... > S[m[n]]
In order for the answer to be correct, n should be as large as possible.
All inequalities are strict: weights must be strictly
increasing, and speeds must be strictly decreasing. There may be many
correct outputs for a given input, your program only needs to find one.
Sample Input
6000 2100
500 2000
1000 4000
1100 3000
6000 2000
8000 1400
6000 1200
2000 1900
Sample Output
4
5
9
7
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=;
struct node{
int weight,speed,id;
}que[maxn];
int dp[maxn],pre[maxn];
bool cmp(struct node t1,struct node t2){
if(t1.weight!=t2.weight)
return t1.weight<t2.weight;
return t1.speed>t2.speed;
} int main(){
int x,y;
int tot;
tot=;
while(scanf("%d%d",&que[tot].weight,&que[tot].speed)!=EOF){
que[tot].id=tot;
tot++;
}
sort(que+,que+tot+,cmp);
memset(dp,,sizeof(dp));
memset(pre,-,sizeof(pre));
dp[]=;
for(int i=;i<tot;i++){
dp[i]=;
for(int j=i-;j>=;j--){
if((que[i].weight>que[j].weight)&&(que[i].speed<que[j].speed)&&dp[i]<dp[j]+){
dp[i]=dp[j]+;
pre[i]=j;
}
}
}
int point,ans=-;
for(int i=;i<tot;i++){
if(dp[i]>ans){
ans=dp[i];
point=i;
}
}
printf("%d\n",ans);
int tmp[maxn];
int cnt=;
for(int i=point;i!=-;i=pre[i]){
// printf("%d\n",que[i].id);
tmp[cnt++]=que[i].id;
}
for(int i=cnt-;i>=;i--)
printf("%d\n",tmp[i]); return ;
}
HDU 1160 DP最长子序列的更多相关文章
- FatMouse's Speed HDU - 1160 最长上升序列, 线性DP
#include<cstdio> #include<cstdlib> #include<cstring> #include<algorithm> usi ...
- ZOJ 1108 FatMouse's Speed (HDU 1160) DP
传送门: ZOJ:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=108 HDU :http://acm.hdu.edu.cn/s ...
- HDU 1069&&HDU 1087 (DP 最长序列之和)
H - Super Jumping! Jumping! Jumping! Time Limit:1000MS Memory Limit:32768KB 64bit IO Format: ...
- HDU 4604 Deque 最长子序列
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4604 Deque Time Limit: 4000/2000 MS (Java/Others) ...
- HDU 4123 (2011 Asia FZU contest)(树形DP + 维护最长子序列)(bfs + 尺取法)
题意:告诉一张带权图,不存在环,存下每个点能够到的最大的距离,就是一个长度为n的序列,然后求出最大值-最小值不大于Q的最长子序列的长度. 做法1:两步,第一步是根据图计算出这个序列,大姐头用了树形DP ...
- HDU 1513 最长子序列
Palindrome Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- 怒刷DP之 HDU 1160
FatMouse's Speed Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Su ...
- HDU 1160 FatMouse's Speed (DP)
FatMouse's Speed Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Su ...
- 最长子序列dp poj2479 题解
Maximum sum Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 44476 Accepted: 13796 Des ...
随机推荐
- JavaWeb学习笔记——javabean与表单
- Java数据库——事务处理
在数据库中执行5条SQL语句,这些SQL语句本身需要保持一致,即要么同时成功,要么同时失败 事务基本操作 //============================================= ...
- 微信H5手指滑动屏蔽微信的默认效果
我们的H5页面放在微信上时,如果你向上滑动或者向下滑动屏幕时,会发现一些微信的特征,譬如:网页由www.baidu.com提供. 去掉这个微信的特征,代码如下: var f; n.addEventLi ...
- 安卓apk与swiper文字版滚动条
浏览器基础端代码 <!-- Swiper --> <div class="swiper-container"> <div class="sw ...
- AJAX笔试面试题汇总
AJAX笔试面试题汇总 Javascript 1. 什么是ajax,为什么要使用Ajax(请谈一下你对Ajax的认识) 什么是ajax: AJAX是“Asynchronous JavaScript a ...
- Owin是什么?
OWIN的英文全称是Open Web Interface for .NET. 如果仅从名称上解析,可以得出这样的信息:OWIN是针对.NET平台的开放Web接口. 那Web接口是谁和谁之间的接口呢?是 ...
- hdu4982 Goffi and Squary Partition (DFS解法)
BestCoder Round #6 B http://acm.hdu.edu.cn/showproblem.php?pid=4982 Goffi and Squary Partition Time ...
- spark
http://www.cnblogs.com/shishanyuan/p/4723604.html?utm_source=tuicool spark presto2.0计算引擎 http://blog ...
- nyoj 613 免费馅饼 广搜
免费馅饼 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 都说天上不会掉馅饼,但有一天gameboy正走在回家的小径上,忽然天上掉下大把大把的馅饼.说来gameboy ...
- svn搬移到gitlab及使用
svn是一款非常简便,易用的源代码管理工具,用了这么多年,对它情有独钟.都说习惯最难改,那为何要搬移到gitlab上呢? 喜欢尝试新东西,前提还是git比较强大,svn有的它都有,svn没有的它也有. ...