题意:

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.

要求输出哪些FatMouse被选中了,按顺序输出。

思路:

最长不下降子序列,且要记录路径。

看代码

代码:

struct node{
int weight, speed, index;
}
mice[10005]; int dp[10005];
int path[10005];
int finalPath[10005]; bool cmp(node a,node b){
if(a.weight==b.weight)
return a.speed>b.speed;
return a.weight<b.weight;
} int main(){
int cn=0;
int t1,t2;
while(scanf("%d%d",&t1,&t2)!=EOF){
++cn;
mice[cn].weight=t1;
mice[cn].speed=t2;
mice[cn].index=cn;
}
sort(mice+1,mice+1+cn,cmp);
rep(i,1,cn){
dp[i]=1;
path[i]=i;
}
rep(i,2,cn){
int temp=0;
int tempPos=i;
rep(j,1,i-1) if(mice[j].weight<mice[i].weight && mice[j].speed>mice[i].speed){
if(dp[j]>temp){
temp=dp[j];
tempPos=j;
}
}
dp[i]=temp+1;
path[i]=tempPos;
}
int ans=-1;
int ansPos=-1;
rep(i,1,cn){
if(dp[i]>ans){
ans=dp[i];
ansPos=i;
}
}
printf("%d\n",ans); int cn2=0;
while(path[ansPos]!=ansPos){
finalPath[++cn2]=mice[ansPos].index;
ansPos = path[ansPos];
}
printf("%d\n",mice[ansPos].index);
rep2(i,cn2,1) printf("%d\n",finalPath[i]); return 0;
}

hdu 1160 FatMouse's Speed(最长不下降子序列+输出路径)的更多相关文章

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

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

  2. hdu 1160 FatMouse's Speed (最长上升子序列+打印路径)

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

  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 (动态规划、最长下降子序列)

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

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

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

  6. HDU 1160 FatMouse's Speed (DP)

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

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

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

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

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

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

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

随机推荐

  1. Linux系列(14) - grep

    简述 grep是在文件当中匹配符合条件的字符串,作用是查找文件内容 格式 grep [选项] 字符串 文件名 选项 -i:忽略大小写 -v:排除指定字符串 -n:显示行号 例子 grep " ...

  2. git pull 时remote: HTTP Basic: Access denied解决方案

    当qian windows用户密码过期更改了密码后,操作git pull 拉取远程仓库代码或git push时报错 如下:remote: HTTP Basic: Access denied  Auth ...

  3. 定要过python二级 选择第3套

    1 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. . 13. 14. 15. 16. 17. (1)说明了一个问题 所谓的方向是从左到右还是从右到左  是看的是步长  步长的 ...

  4. P6657-[模板]LGV 引理

    正题 题目链接:https://www.luogu.com.cn/problem/P6657 题目大意 给出$n\times n$的棋盘,$m$个起点第$i$个为$(1,a_i)$,对应$m$个终点第 ...

  5. P5319-[BJOI2019]奥术神杖【0/1分数规划,AC自动机,dp】

    正题 题目链接:https://www.luogu.com.cn/problem/P5319 题目大意 一个长度为\(n\)的串\(T\),用\(0\sim 9\)填充所有的\(.\). 然后给出\( ...

  6. WPF进阶技巧和实战03-控件(1-控件及内容控件)

    所有控件都继承自System.Windows.Controls.Control类,这个类添加一些基本结构: 设置控件内容对齐方式 (HorizontalContentAlignment,Vertica ...

  7. Python列表操作常用API

    1.列表的概念 (1)列表的定义 列表是Python中一种基本的数据结构.列表存储的数据,我们称为元素.在列表中的每个元素都会有一个下标来与之对应,第一个索引是0,第二个索引是1,依此类推的整数. 列 ...

  8. HTML对溢出的控制:overflow

    用于对超出模块的内容进行控制 overflow的三种参数 1.visible(默认):溢出部分可见 2.hidden:溢出部分隐藏 3.auto:适当加入滚动条 overflow使用方法 1.常用 o ...

  9. ApsNetCore打造一个“最安全”的api接口

    Authentication,Authorization 如果公司交给你一个任务让你写一个api接口,那么我们应该如何设计这个api接口来保证这个接口是对外看起来"高大上",&qu ...

  10. ls命令剖析

    目录 ls命令剖析 资料翻译 SYNOPSIS 使用方式 DESCRIPTION 说明 参数的说明 -l 参数字符的解释 文件权限的解释 FILES 文件夹 实战演练 ls 命令 ls -l 命令 l ...