题解报告:hdu 1160 FatMouse's Speed(LIS+记录路径)
Problem Description
Input
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
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
Sample Output
#include<bits/stdc++.h>
using namespace std;
struct node{
int w,s,index;//w,s,index分别是体重、速度和LIS的下标
}nod[];
bool cmp(node a,node b){return a.s>b.s;}
int dp[],t[];
int main(){
int k=,max1,max2;
while(cin>>nod[k].w>>nod[k].s){nod[k].index=k;dp[k++]=;}
sort(nod+,nod+k,cmp);max1=max2=;memset(t,,sizeof(t));
for(int i=k-;i>;--i){
for(int j=k-;j>i;--j)
if(nod[j].w>nod[i].w&&nod[j].s<nod[i].s&&dp[i]<dp[j]+){dp[i]=dp[j]+;t[i]=j;}//记录最长子序列的下标
if(dp[i]>max1){max1=dp[i];max2=i;}//记录最终的下标号
}
cout<<max1<<endl;
while(max2!=){
cout<<nod[max2].index<<endl;
max2=t[max2];
}
return ;
}
题解报告:hdu 1160 FatMouse's Speed(LIS+记录路径)的更多相关文章
- HDU 1160 FatMouse's Speed 动态规划 记录路径的最长上升子序列变形
题目大意:输入数据直到文件结束,每行两个数据 体重M 和 速度V,将其排列得到一个序列,要求为:体重越大 速度越低(相等则不符合条件).求这种序列最长的长度,并输出路径.答案不唯一,输出任意一种就好了 ...
- HDU 1160 FatMouse's Speed LIS DP
http://acm.hdu.edu.cn/showproblem.php?pid=1160 同样是先按它的体重由小到大排,相同就按speed排就行. 这样做的好处是,能用O(n^2)枚举,因为前面的 ...
- 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 动态规划LIS,路径还原与nlogn优化
HDU - 1160 给一些老鼠的体重和速度 要求对老鼠进行重排列,并找出一个最长的子序列,体重严格递增,速度严格递减 并输出一种方案 原题等于定义一个偏序关系 $(a,b)<(c.d)$ 当且 ...
- 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 (动态规划、最长下降子序列)
FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- hdu 1160 FatMouse's Speed(最长不下降子序列+输出路径)
题意: FatMouse believes that the fatter a mouse is, the faster it runs. To disprove this, you want to ...
- hdu 1160 FatMouse's Speed 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1160 题目意思:给出一堆老鼠,假设有 n 只(输入n条信息后Ctrl+Z).每只老鼠有对应的weigh ...
- HDU 1160 FatMouse's Speed (sort + dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1160 给你一些老鼠的体重和速度,问你最多需要几只可以证明体重越重速度越慢,并输出任意一组答案. 结构体 ...
随机推荐
- 【c++】多重继承与虚继承
派生类的构造函数初始化列表将实参分别传递给每个直接基类,其中基类的构造顺序与派生列表中基类的出现顺序保持一致,而与派生类构造函数初始化列表中基类的顺序无关. 类型转换与多个基类 编译器不会在派生类向基 ...
- Reload file in vim
68down voteaccepted Give this a try: :e From :h :e: Edit the current file. This is useful to re-edit ...
- 【转载】COM文件与EXE文件的区别与联系
COM文件是一种可执行程序的内存映象文件,它与只有16位地址线的8位机上的CP/M操作系统下的可执行程序结构相似.在COM程序执行过程中,除了调用DOS功能和 ROM BIOS 功能,以及用户特意安排 ...
- Ios 项目从头开发 MVVM模式(三)
1.话说,本来想做个聚合查询功能.可是我的重点想研究xmpp聊天功能.所以使用mvvm模式做了全然模式51job主界面的页面. 2.首先给大家看我执行起来的界面. 3.界面非常easy,做这个界面主要 ...
- debian包之间的关系
1 debian包之间存在两大类关系 第一,依赖 第二,冲突 2 依赖类关系 2.1 depends 2.2 pre-depends 2.3 recommends 2.4 suggests 2.5 e ...
- envoy
微服务意味着网络更加依赖于服务抽象边界. 随着相互依赖的服务数量日渐增长,系统100%没问题的时间会变少,整个系统经常有部分功能处于降级状态.
- windows 目录空格
Window下安装Scala出现:此时不应有 \scala\bin\..\lib\jline-2.14.5.jar 原因很简单,scala默认安装到了Program Files (x86)文件夹下,目 ...
- python 获取代码宿主机名 ip
1.获取hostname 相同代码 不同宿主机 日志名 互异 且 可识别宿主机 分布式爬虫 https://docs.python.org/3.6/library/socket.html#socket ...
- [NOI2018] 归程 可持久化并查集
题目描述 本题的故事发生在魔力之都,在这里我们将为你介绍一些必要的设定. 魔力之都可以抽象成一个n 个节点.m 条边的无向连通图(节点的编号从 1至 n).我们依次用 l,a描述一条边的长度.海拔. ...
- ABAP Debug 技巧
小技巧,可以在Debugger的时候跳过不想执行的代码, 或者返回执行已经执行过的代码,实际开发过程中很有帮助