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 <cstdio>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <math.h>
#include <vector>
using namespace std;
#define N 4000
#define ll long long
#define INF 0x3f3f3f3f
#define met(a,b) memset(a,b,sizeof(a));
vector<vector<int> >Q;
struct
node
{

int
p,w,i,l; } s[N];
int
dp[N];
int
cmp(node a,node b)
{

if
(a.w!=b.w)
return
a.w>b.w;
return
a.p<b.p;
}

int
main()
{

int
k=;
while
(scanf("%d%d",&s[k].w, &s[k].p)!=EOF)
{

s[k].i=k+;
s[k].l=-;
k++;
}

sort(s,s+k,cmp);
for
(int i=; i<=k; i++)
dp[i]=;
dp[]=;
int
ans=;
for
(int i=; i<k; i++)
{

for
(int j=; j<i; j++)
{

if
(s[i].p>s[j].p && s[i].w<s[j].w)
{

if
(dp[j]+>=dp[i])
{

dp[i]=dp[j]+;
s[i].l=j;
}
}
if(dp[i]>dp[ans])
ans=i;
}
}

printf("%d\n",dp[ans]);
while
(s[ans].l!=-)
{

printf("%d\n",s[ans].i);
ans=s[ans].l;
}

printf("%d\n",s[ans].i);
return
;
}

(hdu)1160 FatMouse's Speed的更多相关文章

  1. HDU 1160 FatMouse's Speed(要记录路径的二维LIS)

    FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  2. HDU 1160 FatMouse's Speed (动态规划、最长下降子序列)

    FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  3. HDU 1160 FatMouse's Speed (DP)

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

  4. (hdu)5391 Zball in Tina Town

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5391 Problem Description Tina Town is a friendl ...

  5. (hdu)1285 确定比赛名次

    Problem Description 有N个比赛队(<=N<=),编号依次为1,,,....,N进行比赛,比赛结束后,裁判委员会要将所有参赛队伍从前往后依次排名,但现在裁判委员会不能直接 ...

  6. 题解报告:hdu 1160 FatMouse's Speed(LIS+记录路径)

    Problem Description FatMouse believes that the fatter a mouse is, the faster it runs. To disprove th ...

  7. hdu 1160 FatMouse's Speed(最长不下降子序列+输出路径)

    题意: FatMouse believes that the fatter a mouse is, the faster it runs. To disprove this, you want to ...

  8. HDU 1160 FatMouse's Speed(DP)

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

  9. 【最长上升子序列记录路径(n^2)】HDU 1160 FatMouse's Speed

    https://vjudge.net/contest/68966#problem/J [Accepted] #include<iostream> #include<cstdio> ...

随机推荐

  1. 【前端】CSS3实现弹出效果

    36氪这个网站上的登录框弹出的时候挺帅气的,想知道它是怎么做的 .. 今天通过问新爷再加上自己琢磨琢磨写出一个小小Demo - 上代码 <!DOCTYPE html> <html&g ...

  2. mac os的android开发国内库下载地址

    http://ubuntu.buct.edu.cn/android/repository/

  3. SDWebImage 图片加载和缓存

    SDWebImage托管在github上.https://github.com/rs/SDWebImage 这个类库提供一个UIImageView类别以支持加载来自网络的远程图片.具有缓存管理.异步下 ...

  4. maven依赖规则

    1.就近原则,传递依赖 A-B-C -> A-C 2.先声明原则 A-B-C D-E-C 依赖的规则阻止了jar包冲突

  5. 最火的Android开源项目(二)

    在<直接拿来用!最火的Android开源项目(一)>中,我们详细地介绍了GitHub上最受欢迎的TOP20 Android开源项目,引起了许多读者的热议,作为开发者,你最常用的是哪些开源项 ...

  6. 用来理解 Java 编程语言的 8 个图表

    原文地址: http://www.oschina.net/news/44438/top-8-diagrams-for-understanding-java 很多时候,一张图比你说 1000 个字能更有 ...

  7. 牛一网ecshop家电数码模板(仿易迅网)for ecshop 2.7.3

            本模板尤其适用于家电数码行业. 本模板已经开发.测试完毕,并开放演示. 本模板支持全站静态.销售数量后台自定义.首页商品独立图片.品牌独立展示.商品精美团购.宽屏窄屏自动识别并切换.分 ...

  8. 转换流--OutputStreamWriter类与InputStreamReader类

    12.4  转换流--OutputStreamWriter类与InputStreamReader类 整个IO包实际上分为字节流和字符流,可是除了这两个流之外,还存在一组字节流-字符流的转换类. Out ...

  9. GNOME3启动时出错:Oh no! Something has gone wrong.Logout!

    今天用虚拟机安装debian7.1,在启动的时候遇到登录失败的问题,用GNOME Classic可以登录,特地记录如下: 原文出处:http://r3dux.org/2011/11/how-to-fi ...

  10. CentOS7安装小小输入法

    添加epel源 $ sudo yum install epel-release 安装centos7缺失依赖包 libwayland-client $ sudo rpm -Uvh ftp://ftp.p ...