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 7.5 上传文件大小限制

    上传插件:uploadify IIS版本:7.5 描述: 从IIS6升级到IIS7.5以后,网站上传文件大小被限制了,在Chrome下提示:ERR_CONNECTION_RESET,网上的各种方法都试 ...

  2. asp.net core mvc 统一过滤参数,防止注入漏洞攻击

    参考链接: http://www.lanhusoft.com/Article/132.html 在core下,多少有些改动,其中js部分被注释掉了,如下: public static string F ...

  3. python 3.6.5 sys模块和os模块

    1 sys.argv 命令行参数List,第一个元素是程序本身路径 2 sys.exit(n) 退出程序,正常退出时exit(0) 3 sys.version 获取Python解释程序的版本信息 4 ...

  4. SpringMVC之controller篇1

    概述 继 Spring 2.0 对 Spring MVC 进行重大升级后,Spring 2.5 又为 Spring MVC 引入了注解驱动功能.现在你无须让 Controller 继承任何接口,无需在 ...

  5. hdu 5691(状压DP) Sitting in Line

    题目http://acm.hdu.edu.cn/showproblem.php?pid=5691 状态DP,dp[i][j],i 表示的是一种状态,这个状态指的是当前这个数取或不取,j表示的是以第j个 ...

  6. docker 运行 elasticsearch + kibana

    一.elasticsearch的安装 1.从官网上拉取 elasticsearch 的镜像 docker pull elasticsearch:5.6.11docker images 2.运行容器 m ...

  7. oracle:the password has expired

    今天在用dbvisualizer登录数据库的时候,报了the password has expired的错误,于是上网查了一下原因,是因为数据库密码过期了,因为默认的是180天. 解决方法: 1)用系 ...

  8. Hotspot参数分析

    -XX:+HeapDumpOnOutOfMemoryError 让虚拟机在出现内存溢出异常时Dump出当前的内存堆转储快照以便事后进行分析 -Xmx与-Xms 虚拟机堆参数 -Xoss 设置本地方法栈 ...

  9. UI设计:C4D作品案例分享

    中文名4D电影,外文名CINEMA 4D,研发公司为德国Maxon Computer,特点为极高的运算速度和强大的渲染插件,使用在电影<毁灭战士>.<阿凡达>中,获得贸易展中最 ...

  10. Netty 源码 Channel(二)核心类

    Netty 源码 Channel(二)核心类 Netty 系列目录(https://www.cnblogs.com/binarylei/p/10117436.html) 一.Channel 类图 二. ...