题解报告: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 给你一些老鼠的体重和速度,问你最多需要几只可以证明体重越重速度越慢,并输出任意一组答案. 结构体 ...
随机推荐
- 搜索引擎keyword智能提示的一种实现
问题背景 搜索关键字智能提示是一个搜索应用的标配.主要作用是避免用户输入错误的搜索词,并将用户引导到相应的关键词上,以提升用户搜索体验. 美团CRM系统中存在数以百万计的商家,为了让用户高速查找到目标 ...
- [Javascript] Use JavaScript's for-in Loop on Objects with Prototypes
Loops can behave differently when objects have chained prototype objects. Let's see the difference w ...
- 怎样使用SSH连接OpenStack上的云主机
转载请注明出处.否则将追究法律责任http://blog.csdn.net/xingjiarong/article/details/47021815 在上一篇博客中我介绍了怎样在OpenStack中创 ...
- Java第二次作业參考代码
Java第二次作业參考代码 [程序11] 题目:有1.2.3.4四个数字,能组成多少个互不同样且无反复数字的三位数?都是多少? public class lianxi11 { public stati ...
- java数据库连接池技术简单使用
JDBCDemo.java: package com.itheima.jdbc; import java.sql.Connection; import java.sql.PreparedStateme ...
- 菜鸟Sublime日记
一.进行系统安装:www.sublimetext.com/3 选择相应的操作系统,你会发现安装速度惊人的快. 二.安装完成以后,先安装两个基本的插件package control ...
- Android Service 不被杀死并提高优先级
Android Service 不被杀死有两种思路,一种是将APP设置为系统应用.还有一种是增强service的生命力.即使屏幕背光关闭时也能执行. 因为设置为系统应用须要root.所以一般使用后一种 ...
- 深入分析JavaWeb Item13 -- jsp指令具体解释
一.JSP指令简单介绍 JSP指令(directive)是为JSP引擎而设计的.它们并不直接产生不论什么可见输出,而仅仅是告诉引擎怎样处理JSP页面中的其余部分. 在JSP 2.0规范中共定义了三个指 ...
- MFC项目实战(1)文件管理器--界面设计篇
1.创建项目 文件管理器是一个基于对话框的应用程序.首先新建一个“MFC应用程序”类型的项目,然后输入新建项目的名称“FileMng”,并指定该项目保存的位置,单击“确定”按钮,如图所示. 在弹出的“ ...
- Delphi指向函数指针的指针
type TFunc=procedure; procedure MyFunc; begin ShowMessage('Run my func'); end; procedure TForm1.Butt ...