HDU 1160 FatMouse's Speed ——(DP)
又是那个lis变形的题目。
但是不好定义严格的比较符号,因此只能n^2去做。值得注意的一个是要先排序,因为可能可以先选后面的再选前面的,先排序的话就能够避免这个问题。但是要注意,因为要输出路径,所以要记录之前的id。
代码如下:
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <stack>
using namespace std;
const int N = + ;
const int inf = 0x3f3f3f3f; struct node
{
int a,b,id;
bool operator < (const node & temp) const
{
return a == temp.a ? b > temp.b : a < temp.a;
}
}p[N];
struct state
{
int now,pre,len;
}dp[N]; int main()
{
int n = ;
int a,b;
while(scanf("%d%d",&a,&b) == )
{
n++;
p[n] = (node){a,b,n};
//if(n == 9) break;
}
sort(p+,p++n);
for(int i=;i<=n;i++)
{
int pos = -;
for(int j=;j<i;j++)
{
if(!(p[j].a < p[i].a && p[j].b > p[i].b)) continue;
if(pos == -) pos = j;
else if(dp[j].len > dp[pos].len) pos = j;
}
if(pos == -) dp[i] = (state){i,-,};
else dp[i] = (state){i,pos,dp[pos].len + };
}
int ind = ;
for(int i=;i<=n;i++)
{
if(dp[i].len > dp[ind].len) ind = i;
}
stack<int> S;
int temp = ind;
while(ind != -)
{
S.push(ind);
ind = dp[ind].pre;
}
printf("%d\n",S.size());
while(!S.empty())
{
int x = S.top(); S.pop();
printf("%d\n",p[x].id);
}
return ;
}
HDU 1160 FatMouse's Speed ——(DP)的更多相关文章
- HDU 1160 FatMouse's Speed(DP)
点我看题目 题意 :给你好多只老鼠的体重和速度,第 i 行代表着第 i 个位置上的老鼠,让你找出体重越大速度越慢的老鼠,先输出个数,再输出位置. 思路 :看题的时候竟然脑子抽风了,看了好久愣是没明白题 ...
- 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 (动态规划、最长下降子序列)
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 ...
- [HDOJ1160]FatMouse's Speed(DP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1160 FatMouse believes that the fatter a mouse is, th ...
- 题解报告: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 LIS DP
http://acm.hdu.edu.cn/showproblem.php?pid=1160 同样是先按它的体重由小到大排,相同就按speed排就行. 这样做的好处是,能用O(n^2)枚举,因为前面的 ...
- HDU 1160 FatMouse's Speed (sort + dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1160 给你一些老鼠的体重和速度,问你最多需要几只可以证明体重越重速度越慢,并输出任意一组答案. 结构体 ...
- HDU - 1160 FatMouse's Speed 【DP】
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1160 题意 给出一系列的 wi si 要找出一个最长的子序列 满足 wi 是按照升序排列的 si 是按 ...
随机推荐
- Android Studio 代码页跳界面 /java和XML快速切换技巧
https://www.cnblogs.com/simadi/p/6698666.html?utm_source=itdadao&utm_medium=referral 今天又发现了一个And ...
- ubuntu装openssh-client和openssh-server
1. 修改update源 进入/etc/apt/目录,首先用cp命令将sources.list备份成sources.list.bk,然后复制http://www.cnblogs.com/eastson ...
- 为什么领域模型对于架构师如此重要? https://blog.csdn.net/qq_40741855/article/details/84835212
为什么领域模型对于架构师如此重要? https://blog.csdn.net/qq_40741855/article/details/84835212 2018年12月05日 14:30:19 绝圣 ...
- css布局笔记
1.display block块级元素(div.p等) inline 行内元素(a.span等) 常见的例子:把li修改成inline ,制作成水平菜单 2.max-width 来适应不同浏览器窗 ...
- LeetCode 【1】 Two Sum --001
5月箴言 住进布达拉宫,我是雪域最大的王.流浪在拉萨街头,我是世间最美的情郎.—— 仓央嘉措 从本周起每周研究一个算法,并以swift实现之 001 -- Two Sum (两数之和) 题干英文版: ...
- flask自有转换器:int、float、path。默认string
flask自有转换器:int.float.path.默认string # 路由传递的参数默认当做string处理,这里指定int,尖括号中冒号后面的内容是动态的 # -*- coding: utf-8 ...
- navicat for oracle 导入xlsx文件提示无法打开xlsx文件
navicat for oracle 导入xlsx文件提示:无法打开xlsx文件 导入环境: navicat for oracle wps状态的xlsx文件 处理: 将wps状态的xlsx文件,打开方 ...
- JSONPlaceholder - 免费的在线REST服务(提供测试用的HTTP请求假数据)
http://www.hangge.com/blog/cache/detail_2020.html 一.GET 方式请求数据1,获取文章(贴子)数据 二.POST 方式请求数据1,功能说明我们可以将数 ...
- H5中的requestAnimationFrame
这两天做一个公告展示轮播的动画,刚开始是用setinterval写的,后来发现做出来的动画效果有抖动的现象,动画不流畅,遂决定试试requestAnimationFrame,之前也只是耳闻,没有用过, ...
- Window脚本学习笔记之BAT文件处理
BAT文件处理 列出盘中特定文件名的文件: @echo offdir C:\*.jpg /b/s>.\CDatejpg.txt dir C:\*.png /b/s>.\CDatepng.t ...