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
解题思路:将速度降序排,从后往前求最长递减子序列(与LIS的条件相反),同时记录一下LIS的所有下标,每一轮更新一下左端点值max2,最后按着max2=t[max2]沿路打印LIS的所有下标,还有此题是特判,因此只需给出满足条件中的一种即可。
AC代码(15ms):
 #include<bits/stdc++.h>
using namespace std;
struct node{
int w,s,index;//w,s,index分别是体重、速度和LIS的下标
}nod[];
bool cmp(node a,node b){return a.s>b.s;}
int dp[],t[];
int main(){
int k=,max1,max2;
while(cin>>nod[k].w>>nod[k].s){nod[k].index=k;dp[k++]=;}
sort(nod+,nod+k,cmp);max1=max2=;memset(t,,sizeof(t));
for(int i=k-;i>;--i){
for(int j=k-;j>i;--j)
if(nod[j].w>nod[i].w&&nod[j].s<nod[i].s&&dp[i]<dp[j]+){dp[i]=dp[j]+;t[i]=j;}//记录最长子序列的下标
if(dp[i]>max1){max1=dp[i];max2=i;}//记录最终的下标号
}
cout<<max1<<endl;
while(max2!=){
cout<<nod[max2].index<<endl;
max2=t[max2];
}
return ;
}

题解报告:hdu 1160 FatMouse's Speed(LIS+记录路径)的更多相关文章

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

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

  2. HDU 1160 FatMouse's Speed LIS DP

    http://acm.hdu.edu.cn/showproblem.php?pid=1160 同样是先按它的体重由小到大排,相同就按speed排就行. 这样做的好处是,能用O(n^2)枚举,因为前面的 ...

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

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

  4. HDU - 1160 FatMouse's Speed 动态规划LIS,路径还原与nlogn优化

    HDU - 1160 给一些老鼠的体重和速度 要求对老鼠进行重排列,并找出一个最长的子序列,体重严格递增,速度严格递减 并输出一种方案 原题等于定义一个偏序关系 $(a,b)<(c.d)$ 当且 ...

  5. HDU 1160 FatMouse's Speed (DP)

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

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

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

  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 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1160 题目意思:给出一堆老鼠,假设有 n 只(输入n条信息后Ctrl+Z).每只老鼠有对应的weigh ...

  9. HDU 1160 FatMouse's Speed (sort + dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1160 给你一些老鼠的体重和速度,问你最多需要几只可以证明体重越重速度越慢,并输出任意一组答案. 结构体 ...

随机推荐

  1. Hadoop-08-Hive本地独立式安装

    1.安装mysql sudo apt-get install mysql-server mysql-client 2.使用root账户登录mysql数据库,新建存放hive元数据的数据库.如果叫hiv ...

  2. 【Facebook的UI开发框架React入门之八】Image的使用简单介绍(iOS平台)-goodmao

    --------------------------------------------------------------------------------------------------- ...

  3. 微信小程序之 SideBar(侧栏分类)

    项目目录: 模拟数据: utils / data.js function getSData() { var data = [ { "id": 1, "tree" ...

  4. 【转】TestNG执行顺序控制

    1.class执行顺序控制---testng.xml之preserve-order preserve-order:用来控制<test>里面所有<classes>的执行顺序.&l ...

  5. Android5.0(lollipop)新特性介绍(一)

    今年6月的Google I/O大会上.Android L的初次见面我相信让会让非常多android粉丝有些小激动和小期待.当然作为开发人员的我来说,激动不言而喻,毕竟这是自08年以来改变最大的一个版本 ...

  6. Maven实战(七,八)——经常使用Maven插件介绍

    我们都知道Maven本质上是一个插件框架,它的核心并不运行不论什么详细的构建任务,全部这些任务都交给插件来完毕,比如编译源代码是由maven-compiler-plugin完毕的.进一步说,每一个任务 ...

  7. S2SH的集成(Struts2,Spring,Hibernate)----青软S2SH(笔记)

  8. How to Execute Page_Load() in Page's Base Class?

    https://stackoverflow.com/questions/2737092/how-to-execute-page-load-in-pages-base-class We faced th ...

  9. android 改变状态栏(StatusBar)颜色

    public static void changeColor(Activity paramActivity, int paramInt1) { if (Build.VERSION.SDK_INT &g ...

  10. android 设置textview中划线效果

    textView.getPaint().setFlags(Paint. UNDERLINE_TEXT_FLAG ); //下划线   textView.getPaint().setAntiAlias( ...