题意:

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. 怎么让jenkins保持后台运行

    今天在腾讯云直接使用命令启动jenkins,java -jar jenkins.war --httpPort=8080,这样启动关掉shell窗口或退回shell窗口,进程就会结束,需要重新 启动,非 ...

  2. CF757F-Team Rocket Rises Again【最短路,DAG支配树】

    正题 题目链接:https://www.luogu.com.cn/problem/CF757F 题目大意 \(n\)个点\(m\)条边的一张无向图,求删除\(s\)以外的一个点改变\(s\)到最多点的 ...

  3. Winform 控件命名规范

    前言 最近 Winform 项目做得比较多,控件命名规范上常用的能记住,但是有些总要查,写个记录吧.方便以后自己用,大家也可以参考. 标准控件 序号 控件类型简写 控件类型 1 btn Button ...

  4. iOS 15 无法弹出授权弹框之解决方案---Your app uses the AppTrackingTransparency framework, but we are unable to locate the App Tracking Transparency permission request when reviewed on iOS 15.0

    2021年9月30日下午:我正愉快的期盼着即将到来的国庆假期,时不时刷新下appstoreconnect的网址,28号就提上去的包,今天还在审核中....由于这个版本刚升级的xcode系统和新出的iO ...

  5. 宝塔配置vnc+wine实现Q群机器人

    图形界面必备X Window System yum -y groupinstall "X Window System" 安装epel源 yum -y install epel-re ...

  6. MySQL8.0.20下载与安装详细图文教程,mysql安装教程

    MySQL下载与安装(8.0.20版)教程 mysql安装包+mysql学习视频+mysql面试指南视频教程 下载地址: 链接:https://pan.baidu.com/s/1FmLFhGlajBQ ...

  7. 简单Tab切换

    延迟Tab切换,使用css中的flex布局,原生js实现.(京东首页菜单也有此延迟功能哦!) 每天进步一丢丢~~ 1.延迟Tab切换 <!DOCTYPE html> <html la ...

  8. 4 个场景揭秘,如何低成本让容器化应用 Serverless 化?

    作者 | changshuai FaaS 的门槛 Serverless 形态的云服务帮助开发者承担了大量复杂的扩缩容.运维.容量规划.云产品打通集成等责任,使得开发者可以专注业务逻辑.提高交付速度 ( ...

  9. Java秘诀!Java关系运算符介绍

    运算符丰富是 Java 语言的主要特点之一,它提供的运算符数量之多,在高级语言中是少见的. Java 语言中的运算符除了具有优先级之外,还有结合性的特点.当一个表达式中出现多种运算符时,执行的先后顺序 ...

  10. 利用水文分析方法提取山脊线和山谷线(ArcPy实现)

    一.背景 作为地形特征线的山脊线.山谷线对地形.地貌具有一定的控制作用.它们与山顶点.谷底点以及鞍部点等一起构成了地形起伏变化的骨架结构.同时由于山脊线具有分水性,山谷线具有合水性特征,使得它们在地形 ...