HDU 1160(两个值的LIS,需dfs输出路径)
传送门:
http://acm.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): 20100 Accepted Submission(s): 8909
Special Judge
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.
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.
6000 2100
500 2000
1000 4000
1100 3000
6000 2000
8000 1400
6000 1200
2000 1900
4
5
9
7
#include<bits/stdc++.h>
using namespace std;
#define max_v 10050
struct node
{
int w,s,index;
}m[max_v];
int pre[max_v];
int dp[max_v];
bool cmp(node a,node b)
{
if(a.w!=b.w)
return a.w<b.w;
else
return a.s<b.s;
}
void dfs(int i)
{
int num=m[i].index;
if(i!=pre[i])
{
dfs(pre[i]);
}
printf("%d\n",num);
}
int main()
{
//w先升序sort一下,然后按照s做最长下降子序列,最后dfs输出该序列
int n=;
while(~scanf("%d %d",&m[n].w,&m[n].s))
{
m[n].index=n;
n++;
}
sort(m+,m++n,cmp);
pre[]=;
dp[]=;
for(int i=;i<=n;i++)
{
int maxx=;
int maxi=i;
for(int j=i-;j>=;j--)
{
if(m[i].s<m[j].s)
{
if(dp[j]>maxx)
{
maxx=dp[j];
maxi=j;
}
}
}
dp[i]=maxx+;
pre[i]=maxi;
}
int maxx=;
int maxi;
for(int i=;i<=n;i++)
{
if(maxx<dp[i])
{
maxx=dp[i];
maxi=i;
}
}
printf("%d\n",maxx);
dfs(maxi);
return ;
}
HDU 1160(两个值的LIS,需dfs输出路径)的更多相关文章
- HDU - 1160 FatMouse's Speed 动态规划LIS,路径还原与nlogn优化
HDU - 1160 给一些老鼠的体重和速度 要求对老鼠进行重排列,并找出一个最长的子序列,体重严格递增,速度严格递减 并输出一种方案 原题等于定义一个偏序关系 $(a,b)<(c.d)$ 当且 ...
- 题解报告:hdu 1160 FatMouse's Speed(LIS+记录路径)
Problem Description FatMouse believes that the fatter a mouse is, the faster it runs. To disprove th ...
- hdu 1160 FatMouse's Speed (最长上升子序列+打印路径)
Problem Description FatMouse believes that the fatter a mouse is, the faster it runs. To disprove th ...
- hdu 5092 线裁剪(纵向连线最小和+输出路径)
http://acm.hdu.edu.cn/showproblem.php?pid=5092 给一个m*n的矩阵,找到一个纵向的"线"使得线上的和最小并输出这条线,线能向8个方向延 ...
- 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 排序或者通过最短路两种方法解决
题目大意: 给定一堆点,具有x,y两个值 找到一组最多的序列,保证点由前到后,x严格上升,y严格下降,并把最大的数目和这一组根据点的编号输出来 这里用两种方法来求解: 1. 我们可以一开始就将数组根据 ...
- HDU 1160 FatMouse's Speed (DP)
FatMouse's Speed Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Su ...
- 为什么HashMap初始大小为16,为什么加载因子大小为0.75,这两个值的选取有什么特点?
先看HashMap的定义: public class HashMap<K,V>extends AbstractMap<K,V>implements Map<K,V> ...
- HDU 1160 DP最长子序列
G - FatMouse's Speed Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64 ...
随机推荐
- Aaja.pro 未定义
问题描述:安装新系统后,将代码迁至新系统,所有用到ajaxpro框架调用ajax方法时均报“xx未定义”的错: 解决问题的过程 : 1.看看你在前台调用的方法的命名空间,方法名和后台的是否对应.在后台 ...
- textarea的实现
由于限制字数是用原有的 maxlength会有问题,所以用一般会用js控制,今天用到三种: (一)html: <body> <form name=myform action=&quo ...
- FontSize sp 和 dp 的区别
dp不会随着“设置->显示->字体大小”的改变而改变,sp会. sp会随着configeration的配置来scale, dp不会. 所以,什么时候用sp, 什么时候用dp需要斟酌.
- HTML字符实体名称/实体编号
字符实体对英文的大小写敏感! 字符实体一: 显示结果 描述 实体名称 实体编号 空格 < 小于号 < < > 大于号 > > & 和号 & ...
- EBS登陆界面IE显示异常
使用在IE浏览登陆EBS时: 在登陆界面,登录和取消的按钮显示异常: 在进入HOME界面时,显示的职责全为undefined. 原因: 由于IE版本的兼容性. 解决方法: 浏览器 菜单->工具- ...
- 解决C#调试ArcMap断点不能停的问题
问题出在ArcMap bin\ArcMap.exe.config 默认是不支持NET4.0 <startup> <!--<supportedRuntime version=&q ...
- wxpython 创建工具栏和菜单栏
下面看一下关于创建工具栏,状态栏和菜单的方法,看下面一个例子: import wx class ToolBarFrame(wx.Frame): def __init__(self,parent,id) ...
- python大数据
http://blog.csdn.net/xnby/article/details/50782913 一句话总结:spark是一个基于内存的大数据计算框架, 上层包括了:Spark SQL类似Hive ...
- 用Webstorm 运行React-native 工程时,出错:xcrun: error: unable to find utility "instruments", not a developer tool or in PATH
解决方法:在 终端执行如下命令 sudo xcode-select -s /Applications/Xcode.app/Contents/Developer/ 注意:前提是你已经安装了xcode
- java面试题之----数据库事务的四大特性及隔离级别
本篇讲诉数据库中事务的四大特性(ACID),并且将会详细地说明事务的隔离级别. 如果一个数据库声称支持事务的操作,那么该数据库必须要具备以下四个特性: ⑴ 原子性(Atomicity) 原子性是指事务 ...