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 <cstdio>
#include <map>
#include <iostream>
#include<cstring>
#include<bits/stdc++.h>
#define ll long long int
#define M 6
using namespace std;
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
int moth[]={,,,,,,,,,,,,};
int dir[][]={, ,, ,-, ,,-};
int dirs[][]={, ,, ,-, ,,-, -,- ,-, ,,- ,,};
const int inf=0x3f3f3f3f;
const ll mod=1e9+;
struct node{
int w,s,id;
};
node p[];
int dp[],path[];
bool cmp1(node a,node b){
if(a.w==b.w)
return a.s>b.s;
return a.w<b.w;
}
void output(int x){
if(!x) return ;
output(path[x]);
cout<<p[x].id<<endl;
}
int main(){
ios::sync_with_stdio(false);
int ww,ss; int pos=;
while(cin>>ww>>ss){
p[pos].w=ww; p[pos].s=ss;
p[pos].id=pos;
pos++;
}
sort(p+,p+pos,cmp1);
memset(dp,,sizeof(dp));
memset(path,,sizeof(path));
int ans1=-inf;
int pp1=;
for(int i=;i<pos;i++){
int temp=,jj=;
for(int j=;j<i;j++){
if(p[i].s<p[j].s&&p[i].w>p[j].w){
if(temp<dp[j]){
temp=dp[j];
jj=j;
}
}
}
dp[i]=temp+;path[i]=jj;
if(ans1<dp[i]){
ans1=dp[i];
pp1=i;
}
}
cout<<ans1<<endl;
output(pp1);
}
 

hdu 1160 FatMouse's Speed (最长上升子序列+打印路径)的更多相关文章

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

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

  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 动态规划 记录路径的最长上升子序列变形

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

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

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

  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 (sort + dp)

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

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

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

  8. HDU - 1160 FatMouse's Speed 【DP】

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1160 题意 给出一系列的 wi si 要找出一个最长的子序列 满足 wi 是按照升序排列的 si 是按 ...

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

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

随机推荐

  1. js 移动端 多图上传 预览 删除 base64转为url 传给后端

    说下主要的逻辑,首先是利用input type="file",上传文件,然后判断文件类型是否是图片,这里要注意(multiple,安卓一次一张,ios可以多张). 接着把本地图片转 ...

  2. 自己用习惯的idea快捷键笔记

    Ctrl + Space 自动完成(win10下冲突不能用,自己换成 Alt + \ ) 切换方法是菜单中依次打开 file -> settings -> keymap,搜索complet ...

  3. Spring中RedirectAttributes的用法

    RedirectAttributes 是Spring mvc 3.1版本之后出来的一个功能,专门用于重定向之后还能带参数跳转的的工具类.他有两种带参的方式: 第一种: redirectAttribut ...

  4. [转帖]Kerberos和NTLM - SQL Server

    Kerberos和NTLM - SQL Server https://www.cnblogs.com/dreamer-fish/p/3458425.html 当我们使用Windows Authenti ...

  5. python学习笔记(10)--组合数据类型(集合类型)

    集合类型 集合是多个元素的无序组合,每个元素唯一,不存在相同类型,每个元素是不可变类型.用{}表示,元素间用逗号分隔.建立结合类型用{},或set函数,如果是空集合必须用set. >>&g ...

  6. linux audit审计(2)--audit启动

    参考:https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/security_guide/sec- ...

  7. PHPCMS的使用

    1.下载安装phpcms 下载完后解压将install_packages上传到服务器并重命名为phpcms_test: 更改目录文件系统权限: chmod -R 777 phpcms_test 配置n ...

  8. 转 MySQL 日期类型详解

    MySQL 日期类型:日期格式.所占存储空间.日期范围 比较.  日期类型        存储空间       日期格式                 日期范围  ------------ ---- ...

  9. josn的格式化

    public String formatJson(Object obj) { com.alibaba.fastjson.JSONObject json=(com.alibaba.fastjson.JS ...

  10. 配置 BizTalk Server

    使用“基本配置”或“自定义配置”配置 BizTalk Server. 基本配置与自定义配置       如果配置使用域组,则进行“自定义配置”. 如果配置使用自定义组名称而不是默认组名称,则进行“自定 ...