HDU 1160 FatMouse's Speed--经典DP

hdu1160 FatMouse's Speed (dp,记录路径) 题意:输出一组数列,小鼠的体重增加,速度减少,保证这组数列数量最多。 思路:其实是很经典的dp,一个数字排序好后,求最大递增数列,就是有很多细节问题,还有保存路径。用一个数组,把每一组数的前一组位置保留下来,最后用递归输出。 还有就是这道题必须eof才能输出结果,导致我的电脑总是看不到结果,凭运气A。。。 #include #include #include #include 阅读详情

FatMouse's Speed

Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 4910 Accepted Submission(s): 2130
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


最长有序子序列的问题
从后向前DP。
设g[I].W表示第i只老鼠的重量,g[i].S表示第i只老鼠的速度。我们先对Mas进行排序,以W为第一关键字,从小到大,S为第二关键字,从大到小。
设f[i]为g[i]至g[n]最长的序列长度。考虑某一个f[i],则有:
f[i] = max(f[i], f[j]+1) (1<=j<i,且g[i].W> g[j].W,g[i].S < g[j].S)

#include<string.h>
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;


struct mas
{
    int weigt;
    int sped;
    int key;
};


bool cmp(mas x,mas y)
{
    if(x.weigt!=y.weigt)
        return x.weigt<y.weigt;
    else
        return x.sped>y.sped;
}
mas g[1100];
int f[1100];
int main()
{
    int x,y;
    int i=1;
    while(scanf("%d%d",&x,&y)!=EOF)
    {
        g[i].weigt=x;
        g[i].sped=y;
        g[i].key=i;
        i++;
    }
    memset(f,0,sizeof(f));
    sort(g+1,g+i,cmp);
    f[i-1]=1;
    for(int j=i-2; j>=0; j--)
    {
        int max=0;
        for(int k=j+1; k<i; k++)
        {
            if(g[k].sped<g[j].sped&&g[k].weigt>g[j].weigt&&max<f[k])
            {
                max=f[k];
            }
        }
        f[j]=max+1;
    }
    int max1=0;
    int pi;
    for(int j=1; j<i; j++)
    {
        if(f[j]>max1)
        {
            pi=j;
            max1=f[j];
        }
    }
    printf("%d\n",max1);
    for(int j=pi; j<i; j++)
    {
        if(f[j]==max1)
        {
            printf("%d\n",g[j].key);
            max1--;
        }
        if(max1==0)
            break;
    }
    return 0;

}





Simulink仿真避坑指南:如何设置步长、powergui和模块采样时间才能让控制周期更稳定 本文深入解析Simulink仿真中步长、powergui和模块采样时间的协同配置方法,帮助工程师解决控制周期不稳定问题。通过实际案例和参数调优技巧,指导用户精准设置仿真参数,确保电机控制、电力电子系统等工业仿真结果的可靠性。 阅读详情

相关推荐

Lumerical INTERCONNECT 中的自相位调制 (SPM) 仿真实践指南

本文详细介绍了在Lumerical INTERCONNECT中进行自相位调制(SPM)仿真的实践指南。从SPM的基础物理原理出发,深入解析非线性薛定谔方程和克尔效应,到INTERCONNECT中NLSE波导元件的配置技巧,以及时域与频域中SPM效应的观测方法。文章还提供了常见问题排查和进阶联合仿真技巧,帮助用户高效完成从仿真到实测的校准过程。

weixin_42565652的博客 193

HDU1160 FatMouse's Speed —— DP

题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1160 FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 17386Ac...

alince20008的博客 157

pytorch转onnx转paddlepaddle

1.pt转onnx 可查看我之前的文章:https://blog.csdn.net/oyjwin/article/details/117778583?spm=1001.2014.3001.5501

oyjwin的博客 1467

FatMouse's Speed HDU - 1160

FatMouse’s Speed HDU - 1160 题目大意: 题目给出不超过1000组的数据 从1-n编号 每一组包括两个值 一个是重量,一个是速度 要求找出符合下列条件的最长子序列 序列中重量依次增加 速度依次减少 输出他们的编号(可能有多种答案,输出一种即可) 分析: 这个题首先应该先将其中的一个元素排序 然后分析并查找另一个元素的最长子序列 这里我将重量利用sort()进行排序,分析速...

Fighting_Eagle的博客 241

全面解析:时延扩展与相干带宽、多普勒扩展与相干时间——无线通信基础

时延扩展与相干带宽 多径时延扩展与多径衰落 接收机所接收到的信号是通过不同的直射、反射、折射等路径到达接收机。由于电波通过各个路径的距离不同, 因而各条路径中发射波的到达时间不同,造成多径时延扩展。距离不同所以到达接收机的相位也不相同,不同相位的多个信号在接收端叠加, 如果同相叠加则会使信号幅度增强, 而反相叠加则会削弱信号幅度。 这样,接收信号的幅度将会发生急剧变化,就会产生多径衰落。 ...

king阿金 4万+

plotly包安装_Plotly(一)安装指南

plotly,是一个快速完善并崛起的交互式的、开源的绘图库库,Python库则是它的一个重要分支。现已支持超过40种独特的图表类型,涵盖了广泛的统计、金融、地理、科学和三维用例。Plotly 通过JavaScript构建,能基于Web显示实现交互式的可视化效果(Plotly最强大之处之一)。所以它的图形呈现可以方便的显示于Jupyter notebook(基于html)、独立的html中(直接显示...

weixin_35907189的博客 3484

HDU 1160 FatMouse's Speed

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1160 分析:结构体内用一个元素记录每个老鼠的初始编号,然后对体重进行排序,对速度dp(注意体重不相等); 结构体内再用一个元素记录初始编号为i的老鼠在最长序列中上一个是初始编号为j的老鼠 1 #include<iostream> 2 #include<s...

weixin_38170853的博客 91

基于转录逆转的药物重定向 GPS 模型

GPS是一个基于分子结构预测基因表达扰动的开源平台,由三个模块组成:RCL(在LINCS扰动数据上训练抗噪MLP)、GPS4Drugs(预测新化合物的基因表达谱并进行逆转评分)、MolSearch(基于MCTS的分子优化)。平台使用Morgan指纹和Gene Ontology注释作为特征输入,将基因表达扰动离散为三分类标签。训练数据来自LINCS Phase I的18,746个化合物和978个landmark基因,支持四细胞系独立训练,可用于药物重定向与化合物筛选。

听雨草堂 92

Hdu-1160 FatMouse's Speed(lis打印路径)

FatMouse’s Speed(lis打印路径) hdu-1160 lis打印路径,结构体先排序一次 注意pos数组的更新及取出 ac代码(nlogn): #include<bits/stdc++.h> #pragma GCC optimize(2) #define IOS ios_base::sync_with_stdio(0); cin.tie(0); #define ll lo...

sakuyu_10的博客 301

RK3568平台(USB篇)USB基础知识

现象:把USB设备比如Android手机接到PC答1:是USB控制器,是USB控制器内嵌的root hub.答2. windows里已经有了USB的总线驱动程序,接入USB设备后,是"总线驱动程序"知道你是"android phone"提示你安装的是"设备驱动程序"。USB总线驱动程序负责:识别USB设备, 给USB设备找到对应的驱动程序。答3. PC的USB口内部,D-和D+接有15K的下拉电阻,未接USB设备时为低电平USB设备的USB口内部,D-或D+接有1.5K的上拉电阻;

weixin_49303682的博客 1661

BMP390L数字大气压传感器原理图设计,已量产(压力传感器)

在工业设备的室内定位、地下设施监测这类 GPS 信号盲区场景里,气压高度检测的 “靠谱程度” 直接决定了系统的可用性 —— 毕竟谁也不想在地下停车场导航时,设备把 1 楼误判成 3 楼。最近在项目里基于博世 BMP390L 做了硬件电路设计,正好聊聊这款工业级数字气压传感器的硬实力,以及原理图里的那些关键设计细节。

不脱发的程序猿 361

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

半导体器件仿真:双极型晶体管仿真_15.双极型晶体管的高级仿真技术

双极型晶体管(Bipolar Junction Transistor, BJT)是一种重要的半导体器件,广泛应用于放大、开关和调制等电路中。随着半导体技术的发展,对BJT的仿真要求也越来越高。本节将详细介绍双极型晶体管的高级仿真技术,包括器件模型的选择、仿真参数的优化、温度效应的考虑以及噪声分析等。

2401_87715305的博客 1249

FatMouse's Speed(HDU-1160)

一道经典的最长子序列题,不过该题需要维护两个量,体重和速度,所以需要先对一个量进行排序,然后剩下的那个量就可以像处理最长子序列那样做了。 值得一提的是该题需要打印路径,最好的方法是用一个数组pre运用类似链表的结构,来记录路径。 这恰恰就是紫书上数据结构那章例题14中所用的记录最短路路径的方法 。 其中的巧妙和实现细节请读者细细品味。  针对这道题, 由于dp是利用之前计算的结果进行递推得到的,

AC_Arthur的专栏 3536

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

HDU 1160 FatMouse's Speed(dp)

题目链接:HDU 1160 FatMouse's Speed dp,最长上升子序列。 先给老鼠的大小排序,然后就是最长上升子序列了,注意题目要求的是严格的上升和下降,而排序可能把两个相同的排在一起。 #include #include #include #include using namespace std; const int MAX_N = 1000 + 100; stru

fobdddf的专栏 549

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

HDU1160——FatMouse's Speed(DP入门)

http://acm.hdu.edu.cn/showproblem.php?pid=1160 先介绍一下题目的大意: 输入一串序列: w1 s1 w2 s2 ....  .... wn  sn 要求输出w严格递增 ,s严格递减的序列的最大长度。 并且按顺序输出下标。 样例 输入: 6008 1300 6000 2100 500 2000 1000 400

Reverie 821

Devexpress16.2.6破解工具

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

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

hdu 1160 FatMouse's Speed dp

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

哇咔咔 443

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

HDU 1160 FatMouse's Speed(DP)

题意  输入n个老鼠的体重和速度   从里面找出最长的序列  是的重量递增时速度递减 简单的DP  令d[i]表示以第i个老鼠为所求序列最后一个时序列的长度  对与每个老鼠i  遍历所有老鼠j  当(w[i] > w[j]) && (s[i] #include #include using namespace std; const int M=1005; int w[M], s[M], d[

Good morning,good afternoon and good night 1080

HDU1160FatMouse's Speed(DP)

题目链接:传送门biubiubiu··· 分析:题意大概是有若干只老鼠的数据,要找到最大的子序列将他们按照体重从大到小,速度从小到大的顺序输出。记录路径的话在结构数组中开个n记录原始的顺序,然后再用一个l来记录每一个数据的上一个数据,运用dp求出最大的序列。 AC代码: #include&lt;iostream&gt; #include&lt;cstring&gt; #include&lt;alg...

Stark_industry 216

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

Prince_NYing的博客 253

FatMouse's Speed 【HDU - 1160】

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

Meant_To_Be的博客 401
上一篇: SDJZU--E坤哥的难题
下一篇: hdu2098--拆分素数和--数论
evi1743
博客等级 码龄14年 45粉丝 144原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值