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. 【scrapy】创建第一个项目

    1)创建项目命令: scrapy startproject tutorial 该命令将在当前目录下创建tutorial文件夹 2)定义Item Items are containers that wi ...

  2. dva/dynamic

    1.安装: yarn add dva 2.引入: import dynamic from 'dva/dynamic'; * dva路由跳转 * dynamic(app, model, componen ...

  3. 基于UDP的通讯

    XX:那飘过的100~_~{2014/10/03 10:57} UDP是一种面向非连接SOCK_DGRAM,提供无连接服务.数据包以独立包形式发送,不提供无措保证,数据能够丢失或反复. UDP的Ser ...

  4. 搭建Maven私服(使用Nexus)

    搭建私服能够做什么? 1.假设公司开发组的开发环境所有内网.这时怎样连接到在互联网上的Maven中央仓库呢? 2.假设公司常常开发一些公共的组件.怎样共享给各个开发组.使用拷贝方式吗?假设这样,公共库 ...

  5. LightOJ - 1317 Throwing Balls into the Baskets 期望

    题目大意:有N个人,M个篮框.K个回合,每一个回合每一个人能够投一颗球,每一个人的命中率都是同样的P.问K回合后,投中的球的期望数是多少 解题思路:由于每一个人的投篮都是一个独立的事件.互不影响.所以 ...

  6. vim、gvim在windows下中文乱码的终极解决方式

    測试成功,完美解决. 仅仅需改动VIM文件夹以下的这个文件_vimrc. 加油吧,骚年.非常强大的! set encoding=utf-8 set fileencodings=utf-8,chines ...

  7. jdbc 连 oracle 12c

    jdbc 连 oracle 12c,除了连接串要书写正确(如果用PDB,可插拔数据库),必要的JDBC包也是不可或缺的. 比如我,机器本身装了个oracle 10g,然后上面有个java项目,使用jd ...

  8. memmove 和 memcopy

    1.memmove 函数原型:void *memmove(void *dest, const void *source, size_t count) 返回值说明:返回指向dest的void *指针 参 ...

  9. reverse proxy and forward proxy

    1 什么是forward proxy 一句话,client的proxy就是forward proxy. 2 什么是reverse proxy 一句话,server的proxy就是reverse pro ...

  10. 浅谈UML的概念和模型之UML视图

    相信大家都知道UML的全称,统一建模语言(UML是 Unified Modeling Language的缩写)是用来对软件系统进行可视化建模的一种语言.UML为面向对象开发系统的产品进行说明.可视化. ...