hdu1160 FatMouse's Speed 最长上升子序列 LIS

知识导航神器:Obsidian Breadcrumbs 插件全攻略 Parent: 插件Child: Breadcrumbs 用法这样,它就能识别出你和其他笔记的关系。 阅读详情

FatMouse's Speed

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 13391    Accepted Submission(s): 5893
Special Judge


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
 


根据w升序排序,然后对s求最长递减子序列,注意保存每个元素的位置用于最后输出


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <stack>

using namespace std;

//w为体重,s为速度,pos为最初输入时在数组中的位置
struct node {
	int w, s, pos;
}a[1005];

bool cmp(node x, node y) {
	return x.w < y.w;
}

int ans[1005], pre[1005];

int main()
{
	int tw, ts, len;
	len = 0;
	while (~scanf("%d%d", &tw, &ts)) {
		a[len].w = tw;
		a[len].s = ts;
		a[len].pos = len; //记录每个node的在数组中原来的位置,注意此时是从0开始的,回来打印的时候要加1
		len++;
	}

	sort(a, a + len, cmp);  //根据w升序排列

	memset(ans, 0, sizeof(ans));
	ans[0] = 1; //初始化边界
	pre[0] = 0;

	int maxn, index, MAX = 1;  //最长递减子序列长度MAX初始为1
	for (int i = 1; i < len; i++) { //i: 1 -> len - 1
		maxn = 1;  //当前位置i的最长长度初始为1
		index = i; //初始的前驱为i自身
		//考察前面的最优解,即i之前到比a[i].s大的某个位置j的最长子序列长度
		for (int j = 0; j < i; j++) {
			//注意还要满足a[j].w < a[i].w,因为题目要求w严格递增
			if (a[j].s > a[i].s && a[j].w < a[i].w && ans[j] + 1 > maxn) {
				maxn = ans[j] + 1;
				MAX = max(MAX, maxn); //注意更新最大值
				index = j;
			}
		}
		//到当前位置的递减子序列长度最大值是maxn
		ans[i] = maxn;
		//记录前驱,用于最后输出
		pre[i] = index;
	}
	printf("%d\n", MAX);
	int dx;
	//查找最长递减子序列的最后一个元素的位置dx
	for (int i = 0; i < len; i++) {
		if (ans[i] == MAX) {
			dx = i;
			break;
		}
	}
	//用一个栈输出对前驱进行处理
	//注意最后要输出的是刚开始时在数组里的位置
	//当某个元素的前驱是自身的时候说明它就是最长子序列的第一个元素
	//跟并查集找父节点的思想如出一辙
	stack<int> s;
	do {
		s.push(a[dx].pos + 1);
		dx = pre[dx];
	} while (pre[dx] != dx);
	s.push(a[dx].pos + 1);

	//输出经栈处理过的顺序
	while (!s.empty()) {
		printf("%d\n", s.top());
		s.pop();
	}
	return 0;
}


ESP32-S3射频测试与全球认证全栈实践指南 功率谱密度(PSD)和发射功率等级是无线通信设备射频合规的核心基础概念,其物理层原理直接决定自适应测试、阻塞容限及多国认证的通过路径。PSD ≥10 dBm/MHz触发强制性自适应测试,需验证LBT机制与跳频鲁棒性;而16级可编程发射功率等级(-24 dBm至+20 dBm)则为功耗、覆盖与法规平衡提供工程调控维度。该能力广泛应用于低功耗蓝牙IoT终端、智能家居网关及工业无线传感器等场景,尤其在ESP32-S3平台中,需结合eFuse校准、Sigma工具链与QuickTrack认证策略实现从实验室调试到量产 阅读详情

相关推荐

Mmdetection用自己的数据集训练Mask_RCNN

将自己数据的标签写入配置文件,在data前一行添加自己的标签列表,同时在train,val,test中添加classes = classes,如果不添加,模型就会默认读取coco原始数据集的80个标签,与自己的数据集对应不上就会报错。2.打开第二个文件coco_instance.py,将data_root路径改为你自己coco数据集的位置(注意一定要以/结尾),修改输出图片尺寸(根据自己的数据集决定)3.将标注完的数据转为Mask_rcnn训练所需的数据集格式。4.将数据集放到训练代码文件夹中。

m0_64298393的博客 3472

【最长上升子序列LIS+路径记录】HDU-1160 FatMouse's Speed

注解 1、最长上升子序列的变形。先按照题目要求,根据weight升序和speed降序排序,然后是利用最长上升子序列LIS算法,找到符合要求的最长序列。 2、利用pre数组记录路径。 代码 #include <iostream> #include <algorithm> #include <cstring> using namespace std; st...

zhanggirlzhangboy的博客 529

Linux系统下Materials Studio 2020安装避坑指南:从依赖包到许可证配置全流程

本文提供了一份在Linux系统上安装Materials Studio 2020的深度避坑指南。详细解析了从系统依赖包检查、安装流程、许可证配置到Gateway服务部署的全过程,并分享了与Slurm作业调度系统集成的实战经验,旨在帮助用户高效、稳定地完成部署。

weixin_29313547的博客 385

HDU-1160 FatMouse's Speed

链接:http://acm.hdu.edu.cn/showproblem.php?pid=1160 题意:很多老鼠,每个老鼠有w(重量)和s(速度)两个属性,要求选一些老鼠,使他们的w严格递增且s严格递减,输出个数和老鼠的标号 思路:按照w升序排序,再求s的最长上升子序列(LIS),不过要注意的是本题还要求记录路径,为了方便,我用的是O(n^2)的路径存储算法我不会nlogn的,这里...

weixin_30709809的博客 112

哨兵2号遥感影像解析全流程:步骤、算法与AI应用详解

未来,多源数据融合与边缘计算技术的应用将进一步拓展遥感解析的边界。波段合成:选择10m分辨率波段(如B2、B3、B4、B8)进行Layer Stacking,生成多光谱影像。| 分类与识别 | Scikit-Learn、PyTorch | SVM、CNN、K-Means聚类 | 地块分类、目标检测 || 数据预处理 | SNAP、Sen2Cor | 大气校正、几何校正 | L2A产品生成、格式转换 || 波段融合 | ENVI、GDAL | Layer Stacking、重采样 | 多光谱影像合成 |

zhz5214的博客 2710

NMOS管和PMOS管做开关控制电路

NMOS管和PMOS管做开关控制电路

while(1) 3万+

HDU1160(FatMouse's Speed)

题目入口 题意 题目耐心一点看,大概意思就是说每一行给出一只老鼠的体重和速度,然后证明题目中的一个结论:体重增重,速度减慢,很明显就是一个LIS问题的变种。然后输出“最长上升子序列的长度”,以体重作为第一排序标准,然后再以速度做为第二排序标准,体重大的放在后面,速度大的放在前面。 思路 因为题目要输出最长上升子序列输入时候的序号,输入数据的体重和速度都是无序的,要求最长的上升子序列那么需要对这个...

weixin_43808717的博客 317

详解Xilinx FPGA高速串行收发器GTX/GTP(1)--SerDes和GTX的关系

详解Xilinx FPGA高速串行收发器GTX/GTP(1)--SerDes和GTX的关系

孤独的单刀 4350

HDU 1160 FatMouse's Speed 最长上升子序列,重拾DP

最简单的DP。。。并且在被提示了考虑dp[i]为i结尾的子序列的最长子序列,各种姿势还是没做出来。。 把体重降序排列,就变成了求速度的最长上升子序列,输出正是按次要求,也不用再倒序; n n^2复杂度足以;但是LIS有nlogn的算法:点击打开链接 /* *********************************************** Author :angon

卡尔 781

第五章-AllData集成DataSophon作为数据平台功能

🔥🔥 AllData大数据产品是可定义数据中台,以数据平台为底座,以数据中台为桥梁,以机器学习平台为中层框架,以大模型应用为上游产品,提供全链路数字化解决方案。全新会员商业版 X 微信群:https://docs.qq.com/doc/DVHlkSEtvVXVCdEFo

AllDataDC的博客 1637

【APM】在Kubernetes中搭建OpenTelemetry+Loki+Tempo+Grafana链路追踪(实战一,Loki日志中查看链路追踪数据)

这对于那些不能直接控制 JVM 启动参数的应用特别有用,比如通过 JNI (Java Native Interface) 调用 JVM 的应用、脚本中嵌入的 JVM 应用,或者一些服务管理工具自动启动的服务。这为用户提供了一个灵活的架构,可以根据需要选择最适合自己的追踪解决方案,或者根据环境(如开发、测试、生产)的不同配置不同的后端。: OpenTelemetry SDK 提供了丰富的特性,如自动追踪上下文传播、手动追踪跨度的创建与关联、标签和事件的添加等,使得追踪数据更加丰富和有用。

CN_Eden 3241

HDU - 1160 FatMouse's Speed

input: 6008 1300 6000 2100 500 2000 1000 4000 1100 3000 6000 2000 8000 1400 6000 1200 2000 1900    output: 4 4 5 9 7    题目大意: 有cnt组数据,每组有体重和速度两个值,求其最长上升子序列并打印出他...

DDDDDDDDDD4444444444的博客 185

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

HDU 1160 FatMouse's Speed (最长上升子序列+路径输出)

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 p

←_← 449

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

HDU1160 FatMouse's Speed(lis)

FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 20657    Accepted Submission(s): 9154Special Judge   Problem Description Fa...

fighting_yifeng的博客 251

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

Hdu 1160 FatMouse's Speed (LIS路径输出)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1160 题意:给出n个老鼠的重量和速度值(先重量后速度),要求给出一个最长的排列,其中,前一只老鼠的重量严格小于后一只老鼠,而它的速度要严格大于后一只老鼠。排列可能有多种,只要求出一种就可以了。 思路:排序后转化为最长上升子列。 忽略了可能有多种正确排列,白白调试好久…… #include #

whyorwhnt的专栏 966

HDU 1160 FatMouse's Speed

简单DP,最长上升子序列。先对W排序,然后对S做做LIS #include<cstdio> #include<cstring> #include<cmath> #include<stack> #include<vector> #include<algorithm> using namespace std; ...

weixin_34240520的博客 68

hdu1160_FatMouse's Speed 最大上升子序列

FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 14806    Accepted Submission(s): 6521 Special Judge Problem Descript

路漫漫其修远兮 239

HDU 1160 FatMouse's Speed (记录路径的最长上升子序列)

题意 很多肥老鼠认为,长的越肥,奔跑速度就越快,为了反驳这个观点,你现在需要对老鼠的体重和速度进行研究,你要在老鼠序列中找出一个子序列,使得老鼠的体重在增加,但是速度却在减慢 很多肥老鼠认为,长的越肥,奔跑速度就越快,为了反驳这个观点,你现在需要对老鼠的体重和速度进行研究,你要在老鼠序列中找出一个子序列,使得老鼠的体重在增加,但是速度却在减慢 Input 输入以eof结束。 输入中每行有...

EnjoyingAC的博客 383

HDU-1160-FatMouse's Speed(线性DP,LIS)

FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 20784    Accepted Submission(s): 9220Special Judge Problem Description FatM...

随便写写 278

HDU1160 FatMouse's Speed(最长上升子串)

题目链接:http://acm.hdu.edu.cn/game/entry/problem/show.php?chapterid=3&amp;sectionid=2&amp;problemid=4 题目大意:按体重上升,速度下降排序后,提取符合条件的最长子序列,以证明体重越高,速度越慢 参考链接:https://blog.youkuaiyun.com/liyongfan152/article/detail...

weixin_42374305的博客 206

HDU - 1160FatMouse'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

T__TSZ的博客 536

FatMouse's Speed Hdu1160 动态规划 EOF(Ubuntu 下codeblocks 按 Ctrl+D)

FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 16982    Accepted Submission(s): 7511 Special Judge Problem Description

米兰的小科比 594

hdu4283 You Are the One 区间dp 记忆化搜索or递推

You Are the One Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3032    Accepted Submission(s): 1352 Problem Description   The TV s

EventQueue的博客 1792

hdu1503 Advanced Fruits

Advanced Fruits Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2300    Accepted Submission(s): 1169 Special Judge Problem Description

EventQueue的博客 916

hdu5904 LCIS dp

LCIS Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 645    Accepted Submission(s): 300 Problem Description Alex has two sequences 

EventQueue的博客 670
上一篇: poj2249 Binomial Showdown 求组合数
下一篇: hdu1224 Free DIY Tour DFS或者dp
Daemoonn
博客等级 码龄11年 42粉丝 198原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值