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~~~~
  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<iostream>
  4. #include<algorithm>
  5. using namespace std;
  6. const int maxn=;
  7. struct node{
  8. int weight,speed,id;
  9. }que[maxn];
  10. int dp[maxn],pre[maxn];
  11. bool cmp(struct node t1,struct node t2){
  12. if(t1.weight!=t2.weight)
  13. return t1.weight<t2.weight;
  14. return t1.speed>t2.speed;
  15. }
  16.  
  17. int main(){
  18. int x,y;
  19. int tot;
  20. tot=;
  21. while(scanf("%d%d",&que[tot].weight,&que[tot].speed)!=EOF){
  22. que[tot].id=tot;
  23. tot++;
  24. }
  25. sort(que+,que+tot+,cmp);
  26. memset(dp,,sizeof(dp));
  27. memset(pre,-,sizeof(pre));
  28. dp[]=;
  29. for(int i=;i<tot;i++){
  30. dp[i]=;
  31. for(int j=i-;j>=;j--){
  32. if((que[i].weight>que[j].weight)&&(que[i].speed<que[j].speed)&&dp[i]<dp[j]+){
  33. dp[i]=dp[j]+;
  34. pre[i]=j;
  35. }
  36. }
  37. }
  38. int point,ans=-;
  39. for(int i=;i<tot;i++){
  40. if(dp[i]>ans){
  41. ans=dp[i];
  42. point=i;
  43. }
  44. }
  45. printf("%d\n",ans);
  46. int tmp[maxn];
  47. int cnt=;
  48. for(int i=point;i!=-;i=pre[i]){
  49. // printf("%d\n",que[i].id);
  50. tmp[cnt++]=que[i].id;
  51. }
  52. for(int i=cnt-;i>=;i--)
  53. printf("%d\n",tmp[i]);
  54.  
  55. return ;
  56. }

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. QT 初阶 1.3 节 控件的几何排列

    #include "mainwindow.h" #include <QApplication> #include <QHBoxLayout> #includ ...

  2. 云服务程序在启动的时候执行Powershell脚本

    如果在云服务程序启动时候,需要执行Powershell脚本,我们需要将脚本嵌入到程序中,并且编写一个cmd来执行这个脚本,具体如下: 1.编写测试的Powershell脚本:每隔10分钟 检测dns ...

  3. GoLang之网络

    GoLang之网络 Go语言标准库里提供的net包,支持基于IP层.TCP/UDP层及更高层面(如HTTP.FTP.SMTP)的网络操作,其中用于IP层的称为Raw Socket. net包的Dial ...

  4. 查找“CDN、负载均衡、反向代理”等大型网络真实IP地址的方法

    首先,CDN.负载均衡.反向代理还分为很多层,有时查出来的是最外层的 CDN 服务器群,真实的机器是不对外开放的,类似这样的: 用户 → CDN 网络 → 一台或多台真实机器 ↗ CDN Server ...

  5. Python之路【第十五篇】WEB框架

    WEB框架本质 Python的WEB框架分为两类: 1.自己写socket,自己处理请求 2.基于wsgi(Web Server Gateway Interface WEB服务网关接口),自己处理请求 ...

  6. HTML5 LocalStorage 本地存储,刷新值还在

    H5的两种存储技术的最大区别就是生命周期. 1. localStorage是本地存储,存储期限不限: 2. sessionStorage会话存储,页面关闭数据就会丢失. 使用方法: localStor ...

  7. Linux查看软件安装路径

    Linux中查看某 个软件的安装路径(地址)有时显得非常重要.比如某个文件的快速启动项被删除,或者你要建立快速启动项,或者想删除. 添加安装文件等等,很多地方都要用到查案文件安装路径的命令. 这里给大 ...

  8. TCSQL实时列表缓存数据库帮助文档

    [文章作者:张宴 本文版本:v1.1 最后修改:2010.09.03 转载请注明原文链接:http://blog.zyan.cc/tcsql/] 曾经有人提出,一般数据库缓存分为四种.第一种:单个对象 ...

  9. Collection类相关总结

    集合类的框架如下: Collection(接口)    List(接口):允许重复.         ArrayList         Vector         LinkedList    Se ...

  10. [译]Introducing ASP.NET 5

    原文:http://weblogs.asp.net/scottgu/introducing-asp-net-5 ASP.NET 5预览版发布了, 可以在这下载最新的Visual Studio 2015 ...