FatMouse's Speed (贪心+最长严格符合条件子序列DP+路径还原)

『杭电1160』FatMouses 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 possible into a sequence so that the weights are increasin 阅读详情

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.

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

题意:给定 n 只老鼠,每只老鼠有体重和速度,求老鼠的一个最长序列,使得体重严格递增,速度严格递减。给出这个序列的长度,并且输出这个序列中的每只老鼠在输入中的序号。


解题思路:先对所有老鼠排序,第一个关键字体重从小到大,第二关键字速度从大到小。然后求这个序列中的严格符合之前排序条件的最长子序列。
dp[i] 记录以 i 只老鼠作为结尾的最长合法序列的长度,则有状态转移方程 dp[i]=max{dp[j]+1},0<=j<i。

最后输出时,因为我们每一步都是通过之前的某个状态+1得来的,那么我们往回找的时候就可以从最终的最长长度开始,往前找看哪一个状态可以+1得到当前状态,一直这样找到最开始,将答案存在vector中,然后倒叙输出每个老鼠的原本id编号

很好的一个题目!

code:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;
struct node{
    int w,s,id;
    bool operator < (const node &other)const{
        if(w != other.w)
            return w < other.w;
        return s > other.s;
    }
}m[1005];
int dp[1005];

int main(){
    int i,j,k;
    for(i = 0; i < 1005; i++){
        dp[i] = 1;
    }
    for(i = 1; cin >> m[i].w >> m[i].s; i++){
        m[i].id = i;
    }

    sort(m+1,m+i);
    int maxd = 1;
    for(j = 2; j < i; j++){
        for(k = 1; k < j; k++){
            if(m[k].w < m[j].w && m[k].s > m[j].s){
                dp[j] = max(dp[k] + 1,dp[j]);
                if(dp[j] > dp[maxd])
                    maxd = j;
            }
        }
    }
    cout << dp[maxd] << endl;

    vector<int> pos;
    pos.push_back(maxd);
    for(j = maxd-1; j >= 1; j--){
        if(dp[maxd] == dp[j]+1){
            pos.push_back(j);
            maxd = j;
        }
    }
    for(j = pos.size()-1; j >= 0; j--){
        cout << m[pos[j]].id << endl;
    }
    return 0;
}



【GNSS数据处理】赫尔默特(helmert)方差分量估计解析及代码实现 一、背景 helmert方差分量估计是方差-协方差分量估计的一个特例,在近现代测量平差中,我们处理的数据有明显的变化,数据序列中包括粗差,数据类型不再单一等问题。当我们遇到数据类型两类及以上时,可以考虑使用赫尔默特方差分量估计,应用的前提条件是不同类别的数据需要相互独立,这样我们的权阵就是对角阵。 二、引入 我们先用王者荣耀这款游戏引入一下,王者可是撩妹利器,哈哈,就像你有两部手机(安卓和苹果),带妹的时候大概率会用苹果,因为游戏体验方面苹果要优于安卓,带妹的时候不掉帧,不卡顿,不闪退,要操作有操作,有皮肤 阅读详情

相关推荐

Zotero PDF Translate插件实战:DeepL API免费申请与高效翻译配置指南

本文提供Zotero PDF Translate插件配置DeepL API的完整实战指南。详细介绍了如何免费申请DeepL API密钥,解决国内访问问题,并在插件中完成精细配置,实现文献阅读时的无缝划词翻译,大幅提升科研人员和学生的英文文献阅读效率。

rum55的博客 455

FatMouse's Speed HDU - 1160

FatMouse’s Speed HDU - 1160 题意: 胖老鼠认为越胖的老鼠跑的越快,为了证明这个,你想要通过一堆数据证明越胖越慢。 输入:一堆老鼠,一个老鼠一行,到文件结束。每行包括重量,和速度。(不超过1000只老鼠,整数不超过10000) 输出:n个老鼠的数量,n行表示编号,该编号的老鼠必须重量是递增的,速度是递减的。 思路:排序找最长上身序列。 #include&lt...

DeathYmz的博客 732

WinCC ActiveX控件“许可证缺失”故障排查:从注册表修复到系统兼容性全解析

本文深入解析WinCC ActiveX控件报错“未找到许可证信息”的根本原因与解决方案。核心在于系统注册表中控件的设计时许可证密钥丢失或损坏。文章提供了从手动修复注册表、排查64位系统兼容性,到预防性环境部署的全流程专业指南,帮助工程师彻底解决这一常见故障。

oil88的博客 646

FatMouse‘s Speed--最长单调递增子序列--动态规划

问题描述: FatMouse相信:长得越胖的老鼠跑得越快。为了证明这是不对的,你需要搜集老鼠的数据。然后,在这些数据中选取一个尽可能大的子集,从而发现体重不断增长时,速度却不断下降。 输入 输入一群老鼠的资料,每只老鼠占一行。 每只老鼠的数据是一对整数: 第一个表示它的体重(克),第二个表示它的速度(厘米/秒),两个整数的范围是1~10000。 每组测试数据最多包含1000只老鼠的信息。 任何两只老鼠有可能体重相同,或速度相同,甚至体重和速度都完全相同。 输出 输出一系列数据;第一行是数字n; 接着有n行,

Woo~ 911

JESD204B系统设计实战:如何用SYSREF信号搞定多设备时钟同步(附时序图详解)

本文深入探讨了JESD204B系统中SYSREF信号在多设备时钟同步中的关键作用与实现技巧。通过详细分析SYSREF信号的生成、PCB布局和时序调整,提供了一套完整的解决方案,帮助工程师解决高速数据转换器与FPGA协同工作中的时钟同步问题。文章还包含时序图详解和实测调试技巧,助力提升系统性能。

weixin_29313239的博客 454

风光储互补微电网在偏远地区的应用实践:从建模到仿真全解析

本文深入解析了风光储互补微电网在偏远地区的应用实践,从系统设计到仿真建模全流程。通过Simulink等工具进行动态仿真,验证了系统在多种工况下的可靠性,并结合实际案例展示了其显著的经济和环保效益。文章为从业者提供了从技术路径到实施优化的全面指导。

weixin_29047545的博客 269

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 sequenc...

li_wen_zhuo的博客 527

告别功能限制:Win11家庭版无损升级专业版全攻略

本文详细介绍了如何将Win11家庭版无损升级到专业版的全过程,包括升级前的准备、两种官方升级方案(Microsoft Store购买和使用产品密钥)以及命令行升级方法。升级后可解锁远程桌面、组策略编辑器和BitLocker加密等高级功能,适合需要更多商业功能的用户。

weixin_32822843的博客 697

FatMouse's Speed(dp胖老鼠)

问题描述 FatMouse认为,鼠标越胖,它的运行速度就越快。为了证明这一点,您希望将数据收集到一组小鼠上,并将这些数据的尽可能大的子集放入序列中,以使权重增加,但速度却降低。 输入值 输入包含一堆鼠标的数据,每行一只鼠标,由文件末尾终止。特定鼠标的数据将由一对整数组成:第一个整数表示以克为单位的大小,第二个整数表示以厘米/秒为单位的速度。两个整数都在1到10000之间。每个测试用例中的数据将包含...

xuhang513的博客 1287

基于HetConv与Dual策略的YOLOv8轻量化设计-CSPHet结构的优化与实现

在计算机视觉中,YOLOv8作为目标检测领域的最新版本,通过引入多种改进来提升检测精度和速度。然而,提升精度和保持实时性能往往需要更多参数与计算量。本文提出一种结合Dual思想与HetConv的新型轻量化结构,称为CSPHet。CSPHet能够在保持YOLOv8检测精度的基础上有效减少约70万参数量,实现模型的轻量化和速度的提升。HetConv(Heterogeneous Convolution)是一种混合卷积技术,通过同时使用1x1、3x3等不同大小的卷积核,来捕捉不同尺度的特征。

博客 1323

Qwen2-VL出现RuntimeError: CUDA error: too many resources requested for launch CUDA kernel errors的解决方案

本文主要介绍了Qwen2-VL出现RuntimeError: CUDA error: too many resources requested for launch CUDA kernel errors的解决方案,希望能对使用Qwen2-VL的同学们有所帮助。 文章目录 1. 问题描述 2. 解决方案

weixin_43178406的博客 13万+

动态规划----FatMouse’s Speed(HDU 1160)

HDU 1160 —— FatMouse’s Speed 给定 n 只老鼠,每只老鼠有体重和速度,求老鼠的一个最长序列,使得体重严格递增,速度严格递减。给出这个序列的长度,并且输出这个序列中的每只老鼠在输入中的序号。 解题思路:先对所有老鼠排序,第一个关键字体重从小到大,第二关键字速度从大到小。然后求这个序列中的最长严格递增子序列。 dp[i] 记录以 i 只老鼠作为结尾的最长合

wy19910326的专栏 938

【AI黑话日日新】什么是AI云原生?

云原生赋能AI:利用容器、微服务、Serverless、DevOps等云原生技术,解决AI应用(尤其是大模型)在部署、扩展、运维、成本控制方面的痛点,让AI服务具备高可用、高性能、易运维、易扩展的特性AI赋能云原生:将AI技术(如智能调度、异常检测、自动优化)融入云基础设施管理,使云平台具备自我感知、自我优化、自我修复的能力,从"被动响应"升级为"主动适配"其本质是实现从""(AI运行在云上)到""(为AI量身打造的云)的根本性转变。

专注:太空算力、AI infra、异构调度、大模型成本工程 627

FatMouse's Speed【DP最长上升子序列】

  题目链接(无图)   题目链接(有图) FatMouse认为鼠标越胖,运行速度就越快。为了证明这一点,您希望将数据放在一组鼠标上,并将尽可能大的数据子集放入序列中,以便权重增加,但速度会降低。  输入 输入包含一堆鼠标的数据,每行一个鼠标,由文件末尾终止。 特定鼠标的数据将由一对整数组成:第一个以克为单位表示其大小,第二个以厘米每秒表示其速度。两个整数都在1到10000之间。每个测试用...

既然弱小,就只顾变强就是了 471

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

DP-HDU-1160-FatMouse's Speed

FatMouse’s SpeedTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 12405 Accepted Submission(s): 5446 Special JudgeProblem Description FatMou

懒鬼的私人泳池 649

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

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

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...

菜鸡的博客 574

HDU -- FatMouse's Speed(ACM Step: 3.2.4)

一、概述 1. 问题描述 许多大老鼠在讨论一个问题:是不是咱们越胖跑得越快呢?现在需要我们去否定这个思想,给出n个老鼠的体重和速度,需要找出这样的一个老鼠序列:体重递增而速度递减,要求找到最长的序列来否定老鼠的猜想! 2. 问题链接 HDU -- FatMouse's Speed(ACM Step: 3.2.4) 3. 问题截图 图1.1  问题截图 二、算法思路 由于ACM ...

hexiaole1994的专栏 487

FatMouse's Speed(DP-记录路径)

#include<iostream> #include<cstdio> #include<algorithm> #include<cmath> #include<cstring> #include<map> #include<queue> #include<utility> #include<se...

桃夭丶的博客 266

FatMouse's Speed HDU - 1160 (线性dp)

                                                 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...

森宝的博客 424

FatMouse's Speed 动规小练

FatMouse’s Speed 原题链接https://vjudge.net/contest/349774#problem/G 题目要求找出对于体重增大速度减小这一条件的最多小鼠 对于此条件进行排序 然后由链长来反推出每个数据的位置,根据题目同长度有很多情况,只需要输出一种即可 当然 学了并查集之后也可以用pre来记录,查找父节点来输出 说实话我感觉我这种方法有问题,但是不管是bfs最后一题...

yeyuluo的博客 339

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

FatMouse‘s Speed(LIS)

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

qq_45928501的博客 317

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 pos...

cheerful_man的博客 316
上一篇: Students in Railway Carriage (思维)
下一篇: Escape HDU - 3533 (BFS)
Guuuuuu老师儿
博客等级 码龄9年 259粉丝 718原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值