hdu 1160 FatMouse's Speed(最长不下降子序列+输出路径)
题意:
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(最长不下降子序列+输出路径)的更多相关文章
- HDU 1160 FatMouse's Speed (最长上升子序列)
题目链接 题意:n个老鼠有各自的重量和速度,要求输出最长的重量依次严格递增,速度依次严格递减的序列,n最多1000,重量速度1-10000. 题解:按照重量递增排序,找出最长的速度下降子序列,记录序列 ...
- hdu 1160 FatMouse's Speed (最长上升子序列+打印路径)
Problem Description FatMouse believes that the fatter a mouse is, the faster it runs. To disprove th ...
- HDU 1160 FatMouse's Speed(要记录路径的二维LIS)
FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU 1160 FatMouse's Speed (动态规划、最长下降子序列)
FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU 1160 FatMouse's Speed 动态规划 记录路径的最长上升子序列变形
题目大意:输入数据直到文件结束,每行两个数据 体重M 和 速度V,将其排列得到一个序列,要求为:体重越大 速度越低(相等则不符合条件).求这种序列最长的长度,并输出路径.答案不唯一,输出任意一种就好了 ...
- HDU 1160 FatMouse's Speed (DP)
FatMouse's Speed Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Su ...
- HDU 1160 FatMouse's Speed (sort + dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1160 给你一些老鼠的体重和速度,问你最多需要几只可以证明体重越重速度越慢,并输出任意一组答案. 结构体 ...
- HDU - 1160 FatMouse's Speed 动态规划LIS,路径还原与nlogn优化
HDU - 1160 给一些老鼠的体重和速度 要求对老鼠进行重排列,并找出一个最长的子序列,体重严格递增,速度严格递减 并输出一种方案 原题等于定义一个偏序关系 $(a,b)<(c.d)$ 当且 ...
- HDU - 1160 FatMouse's Speed 【DP】
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1160 题意 给出一系列的 wi si 要找出一个最长的子序列 满足 wi 是按照升序排列的 si 是按 ...
随机推荐
- POJ1426——Find The Multiple (简单搜索+取余)
题意: 给一个数n,让你找出一个只有1,0,组成的十进制数,要求是找到的数可以被n整除. 用DFS是搜索 当前位数字 (除最高位固定为1),因为每一位都只有0或1两种选择,换而言之是一个双入口BFS. ...
- Docker入门系列之一:什么是Docker?
原文作者:Jeff Hale 原文地址:https://towardsdatascience.com/learn-enough-docker-to-be-useful-b7ba70caeb4b 翻译: ...
- jQuery <= 1.11.3 DomXSS漏洞
听团里说WordPress又爆跨站漏洞了:" XSS漏洞在Jetpack和二十五默认主题影响百万WordPress用户 ",分析发现原来是jQuery老版本的DOM XSS漏洞[错 ...
- Nginx系列(6)- nginx: [error] CreateFile() "D:\nginx-1.20.1/logs/nginx.pid" failed (2: The system cannot find the file specified)
背景 修改nginx配置文件nginx.conf后,想要重启nginx使配置生效.cmd进入nginx安装目录,输入命令: nginx -s reload 报错:nginx: [error] Crea ...
- vue 学习资料
自学资料地址: https://zhuanlan.zhihu.com/p/26535530项目UI部分1.pc站 UI:(1)考虑自己写成本高,需要花费不少时间,好处是可以自己控制维护!(2)引入第三 ...
- 《exe应用程序UI自动化》
前言:有很多公司做一些客户端的应用,每次发版都要耗费人力去手动回归比较费时,那么我们就想着去怎么去驱动人为的操作变为机器的操作过程,当然想着进行UI自动 那么我们就要考虑怎么去实现exe应用程序的自动 ...
- P6499-[COCI2016-2017#2]Burza【状压dp】
正题 题目链接:https://www.luogu.com.cn/problem/P6499 题目大意 \(n\)个点的一棵树,开始有一个棋子在根处,开始先手选择一个点封锁,然后后手封锁棋子所在点然后 ...
- mybatis多种查询方法
1. 查询单行,对象,并封装成一个对象 Employee getEmpById(Integer id); <select id="getEmpById" resultType ...
- .Net微服务实战之可观测性
系列文章 .Net微服务实战之技术选型篇 .Net微服务实战之技术架构分层篇 .Net微服务实战之DevOps篇 .Net微服务实战之负载均衡(上) .Net微服务实战之CI/CD .Net微服务实战 ...
- golang实现一个简单的websocket聊天室
基本原理: 1.引入了 golang.org/x/net/websocket 包. 2.监听端口. 3.客户端连接时,发送结构体: {"type":"login" ...