又是那个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)的更多相关文章

  1. HDU 1160 FatMouse's Speed(DP)

    点我看题目 题意 :给你好多只老鼠的体重和速度,第 i 行代表着第 i 个位置上的老鼠,让你找出体重越大速度越慢的老鼠,先输出个数,再输出位置. 思路 :看题的时候竟然脑子抽风了,看了好久愣是没明白题 ...

  2. HDU 1160 FatMouse's Speed(要记录路径的二维LIS)

    FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  3. HDU 1160 FatMouse's Speed (动态规划、最长下降子序列)

    FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  4. hdu 1160 FatMouse's Speed(最长不下降子序列+输出路径)

    题意: FatMouse believes that the fatter a mouse is, the faster it runs. To disprove this, you want to ...

  5. [HDOJ1160]FatMouse's Speed(DP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1160 FatMouse believes that the fatter a mouse is, th ...

  6. 题解报告:hdu 1160 FatMouse's Speed(LIS+记录路径)

    Problem Description FatMouse believes that the fatter a mouse is, the faster it runs. To disprove th ...

  7. HDU 1160 FatMouse's Speed LIS DP

    http://acm.hdu.edu.cn/showproblem.php?pid=1160 同样是先按它的体重由小到大排,相同就按speed排就行. 这样做的好处是,能用O(n^2)枚举,因为前面的 ...

  8. HDU 1160 FatMouse's Speed (sort + dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1160 给你一些老鼠的体重和速度,问你最多需要几只可以证明体重越重速度越慢,并输出任意一组答案. 结构体 ...

  9. HDU - 1160 FatMouse's Speed 【DP】

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1160 题意 给出一系列的 wi si 要找出一个最长的子序列 满足 wi 是按照升序排列的 si 是按 ...

随机推荐

  1. 基于【 MySql 】一 || 主从复制

    一.centos7安装mysql 1. 先检查系统是否装有mysql rpm -qa | grep mysql 2. 下载mysql的repo源 wget http://repo.mysql.com/ ...

  2. 【大数据】Clickhouse基础知识

    第1章 ClickHouse概述 1.1 什么是ClickHouse ClickHouse 是俄罗斯的Yandex于2016年开源的列式存储数据库(DBMS),主要用于在线分析处理查询(OLAP),能 ...

  3. 连接MySQL报错误代码 ERROR 1045时的解决方案

            最近在做网站迁移的时候,遇到了一件很尴尬的事情,远程连接数据连不上了,一直报 错误号码1045 Access denied for user 'root'@xx.xxx.xxx.xx( ...

  4. Python asyncio 模块

    Python 3.4 asyncio是Python 3.4版本引入的标准库,直接内置了对异步IO的支持. asyncio的编程模型就是一个消息循环.我们从asyncio模块中直接获取一个EventLo ...

  5. 【16】大调 Leading Bass

    一小节2拍: (歌曲举例子) 菊花台(主).知足(主).青春修炼手册(副).记得(副).当你(副). 一小节1拍: (歌曲举例子) 菊花台(主).知足(主).青春修炼手册(副).记得(副).当你(副) ...

  6. 迭代器 Iterator 是什么?(未完成)Iterator 怎么使用?(未完成)有什么特点?(未完成)

    迭代器 Iterator 是什么?(未完成)Iterator 怎么使用?(未完成)有什么特点?(未完成)

  7. linux(3)

    一.用户和组的管理 Linux/Unix是多用户系统: root是超级用户,拥有最高权限.其它用户及权限由root来管理.对比Windows系统: 控制面板 -> 管理工具 -> 计算机管 ...

  8. Windows Media Player播放视频导致程序闪退

    在有的电脑上发现,使用Windows Media Player组件播放视频导致程序闪退. 发现是显卡问题,独立显卡换成集成显卡 解决: 打开显卡控制面板->管理3D设置->集成图形-> ...

  9. go语言defer关键字背后的实现,语法,用法

    原文: https://tiancaiamao.gitbooks.io/go-internals/content/zh/03.4.html ------------------------------ ...

  10. 一、vue基础--语法

      用到的前台编程工具是Visual Studio Code,暂时是官网下载vue.js到本地使用 一.Visual Studio Code需要安装的插件: jshint :js代码规范检查 Beau ...