http://acm.hdu.edu.cn/showproblem.php?pid=1160

FatMouse's Speed

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 12338    Accepted Submission(s): 5405
Special Judge

Problem 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
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm> using namespace std;
#define N 10005
#define oo 0x3f3f3f3f /** 感觉有点用导弹防御的思想
每次记录从 0 到 i 的最长个数
并用 pre[i] 记录 i 点是从哪个点过来的 **/ /// number 是记录它原来的位置 struct node
{
int w, s, number;
}a[N]; /// pre[] 是个很好的记录方式,可以记录它的是从哪个过来的(它的上一步) int dp[N], pre[N]; /// 先按 w 从小到大排, 再按 s 从大到小排
int cmp(node n1, node n2)
{
if(n1.w!=n2.w)
return n1.w < n2.w;
return n1.s > n2.s;
} int main()
{
int i=, j, n; memset(a, , sizeof(a));
memset(dp, , sizeof(dp)); while(scanf("%d%d", &a[i].w, &a[i].s)!=EOF)
{
a[i].number = i;
i++;
} n=i;
sort(a+, a+i+, cmp); /**
for(i=1; i<n; i++)
printf("%d %d %d\n", a[i].number, a[i].w, a[i].s);
**/ for(i=; i<n; i++)
{
pre[i] = i;
dp[i] = ;
for(j=; j<i; j++)
{
if(a[i].w!=a[j].w && a[i].s<a[j].s)
{
if(dp[i]<dp[j]+)
{
pre[i] = j;
dp[i] = dp[j] + ;
}
}
}
} int Max=-oo, index=; for(i=; i<n; i++)
{
if(dp[i]>Max)
{
Max = dp[i];
index = i;
}
} printf("%d\n", Max);
i=;
int b[N]={};
while(pre[index]!=index)
{
b[i++] = a[index].number;
index = pre[index];
} printf("%d\n", a[index].number);
for(j=i-; j>=; j--)
printf("%d\n", b[j]); return ;
}

(最长上升子序列 并记录过程)FatMouse's Speed -- hdu -- 1160的更多相关文章

  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 - 1160 最长上升子序列以及记录路径

    题意:第一列,给出老鼠的重量,第二列,给出老鼠的速度,要证明老鼠的重量越大,速度越小,给出最多老鼠的数量,并说明第几只. 思路:先将老鼠按照重量从大到小排序,然后速度是从小到大,求最长上升子序列,学习 ...

  4. CSU 1225 最长上升子序列并记录其个数

    ;j<i;j++){ if(h[i] > h[j]){ ) cnt[i]+=cnt[j]; ) len[i] = len[j] + , cnt[i] = cnt[j]; } //身高相同的 ...

  5. - > 动规讲解基础讲解七——最长单增子序列

    (LIS Longest Increasing Subsequence)给定一个数列,从中删掉任意若干项剩余的序列叫做它的一个子序列,求它的最长的子序列,满足子序列中的元素是单调递增的. 例如给定序列 ...

  6. HDU 1160 FatMouse's Speed(DP)

    点我看题目 题意 :给你好多只老鼠的体重和速度,第 i 行代表着第 i 个位置上的老鼠,让你找出体重越大速度越慢的老鼠,先输出个数,再输出位置. 思路 :看题的时候竟然脑子抽风了,看了好久愣是没明白题 ...

  7. HDU 1160 FatMouse's Speed 动态规划 记录路径的最长上升子序列变形

    题目大意:输入数据直到文件结束,每行两个数据 体重M 和 速度V,将其排列得到一个序列,要求为:体重越大 速度越低(相等则不符合条件).求这种序列最长的长度,并输出路径.答案不唯一,输出任意一种就好了 ...

  8. HDU - 1503 最长公共子序列记录路径

    题意:先给两个水果的名字然后得出一个最短的序列包含这两个词. 思路:我一开始的思路是先求出最长公共子序列,然后做一些处理将其他的部分输出来:两种水果的字符串和最长公共子序列的字符串这三个字符串做对比, ...

  9. HDU 1160 FatMouse's Speed (最长上升子序列)

    题目链接 题意:n个老鼠有各自的重量和速度,要求输出最长的重量依次严格递增,速度依次严格递减的序列,n最多1000,重量速度1-10000. 题解:按照重量递增排序,找出最长的速度下降子序列,记录序列 ...

随机推荐

  1. IIS站点报拒绝访问Temporary ASP.NET Files的解决办法

    IIS站点本来运行的好好的,突然就出现了:Temporary ASP.NET Files拒绝访问的问题.遇到此类问题,请逐步排查,定可解决. 原因:Windows操作系统升级导致. 办法: 1.检查C ...

  2. python 网络下载的三种风格 未完成

    import osimport timeimport sys import requests#依序下载POP20_CC = ('CN IN US ID BR PK NG BD RU JP' 'MX P ...

  3. iOS.CM5.CM4.CM2

    增量数据计算接口: CC_MDx_Init CC_MDx_Update CC_MDx_Final 全量数据计算接口: CC_MDx

  4. 洛谷1984 [SDOI2008]烧水问题

    一道找规律 原题链接 显然要将烧得的温度最大化利用,即每次都去热传递. 设水沸腾为\(x\). 第一杯直接烧水,需提高\(x\). 第二杯先与第一杯进行热传递,这样只需提高\(\dfrac{x}{2} ...

  5. 用PS绘制立体字的效果教程

    1. 新建一个透明画布. 2. 利用选区绘制一个圆圈 3. 利用渐变工具绘制渐变 (颜色自拟) 4. 选择混合器画笔工具按住ALT 点击填充颜色的图层 5. 新建画布填充黑色 利用混合画笔进行绘制. ...

  6. ArrayList、Vector、LinkedList的特点和区别

    ArrayList.Vector.LinkedList类均在java.util包中,均为可伸缩数组. 1)ArrayList和Vector都是基于存储元素的Object[] array来实现的,它们会 ...

  7. Vue 使用中的小技巧

    在vue的使用过程中会遇到各种场景,当普通使用时觉得没什么,但是或许优化一下可以更高效更优美的进行开发.下面有一些我在日常开发的时候用到的小技巧,在下将不定期更新~ 1.多图表resize事件去中心化 ...

  8. Java SE学习【三】——JDBC

    最近学到了数据库与java的jdbc方面,还有个DAO模式,写一下自己的理解,后期有什么不对的再改. 一.数据库三范式的理解 记得以前上课时,也上了一学期的“数据库系统原理”,给我们上课的老师算是渣渣 ...

  9. Oracal 学习之用户角色创建分配表空间 给角色分配权限

    //创建角色inspur 密码为inspur,默认的表空间为USERS create user inspur identified by inspur default tablespace USERS ...

  10. 【Web】Nginx Rewrite规则

    Rewrite介绍 Rewrite主要的功能就是实现URL的重写,Nginx的Rewrite规则采用Pcre,perl兼容正则表达式的语法规则匹配,如果需要Nginx的Rewrite功能,在编译Ngi ...