G - FatMouse's Speed

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Appoint description:

Description

FatMouse believes that the fatter a mouse is, the faster it runs. To disprove this, you want to take the data on a collection of mice and put as large a subset of this data as possible into a sequence so that the weights are increasing, but the speeds are decreasing.
 

Input

Input contains data for a bunch of mice, one mouse per line, terminated by end of file.

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

Your program should output a sequence of lines of data; the first line
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

6008 1300
6000 2100
500 2000
1000 4000
1100 3000
6000 2000
8000 1400
6000 1200
2000 1900
 

Sample Output

4
4
5
9
7
 
 
正常一个·变量的求法变为结构体封装,,,,,,额外加一个pre数组记录回溯路径
1A~~~~
#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最长子序列的更多相关文章

  1. FatMouse's Speed HDU - 1160 最长上升序列, 线性DP

    #include<cstdio> #include<cstdlib> #include<cstring> #include<algorithm> usi ...

  2. 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 ...

  3. HDU 1069&&HDU 1087 (DP 最长序列之和)

    H - Super Jumping! Jumping! Jumping! Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format: ...

  4. HDU 4604 Deque 最长子序列

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4604 Deque Time Limit: 4000/2000 MS (Java/Others)     ...

  5. HDU 4123 (2011 Asia FZU contest)(树形DP + 维护最长子序列)(bfs + 尺取法)

    题意:告诉一张带权图,不存在环,存下每个点能够到的最大的距离,就是一个长度为n的序列,然后求出最大值-最小值不大于Q的最长子序列的长度. 做法1:两步,第一步是根据图计算出这个序列,大姐头用了树形DP ...

  6. HDU 1513 最长子序列

    Palindrome Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  7. 怒刷DP之 HDU 1160

    FatMouse's Speed Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Su ...

  8. HDU 1160 FatMouse's Speed (DP)

    FatMouse's Speed Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Su ...

  9. 最长子序列dp poj2479 题解

    Maximum sum Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 44476   Accepted: 13796 Des ...

随机推荐

  1. Java反射机制<1>

    如果要通过一个对象找到一个类的名称,此时就需要用到反射机制(反射技术是用来做框架的,一般情况下Java私有对象不能被访问,但是暴力反射可以访问私有对象). 任何一个类如果没有明确地声明继承自哪个父类的 ...

  2. System类

    System类是一些与系统相关属性和方法的集合,而且System类中所有的属性都是静态的,要想引用这些属性和方法,直接使用System类调用即可. //======================== ...

  3. HTML学习笔记——选择器

    1> ID选择器.交叉选择器.群组选择器.子代选择器 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN& ...

  4. TCP/IP协议详解 卷1—读书笔记(1)

    0. 前言 本系列简要记录该书的关键点,用以梳理知识点. 1. 简介 简述链路层下的一些相关协议,如以太网IP数据报,802标准,SLIP,CSLIP,PPP. 链路层主要为上层(IP)和本层(ARP ...

  5. jsp总结

    JSP 定义:    1)Java Server Page, Java EE 组件,本质上是 Servlet.    2)运行在 Web Container.接收 Http Request,生成 Ht ...

  6. js其它

    1.js的数组           * 什么是数组?                        - 使用变量,var m = 10;                        - java里面 ...

  7. array_map与array_column之间的关系

    /*|----------------------------------------------------------|array_map();将回调函数作用到给定数组的单元上|array_col ...

  8. Java并发编程核心方法与框架-ExecutorService的使用

    在ThreadPoolExecutor中使用ExecutorService中的方法 方法invokeAny()和invokeAll()具有阻塞特性 方法invokeAny()取得第一个完成任务的结果值 ...

  9. elasticsearch集群管理工具head插件(转)

    elasticsearch-head是一个elasticsearch的集群管理工具,它是完全由html5编写的独立网页程序,你可以通过插件把它集成到es 插件安装方法1: 1.elasticsearc ...

  10. C# 正则分组捕获

    分组语法 捕获 (exp) 匹配exp,并捕获文本到自动命名的组里 (?<name>exp) 匹配exp,并捕获文本到名称为name的组里,也可以写成(?'name'exp) (?:exp ...