链接:

https://vjudge.net/problem/HDU-1160

题意:

FatMouse believes that the fatter a mouse is, the faster it runs. To disprove this, you want to take the data on a collection of mice and put as large a subset of this data as possible into a sequence so that the weights are increasing, but the speeds are decreasing.

思路:

对s排序, 然后最长递增子序列,nlogn总有bug还是n2好用

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
//#include <memory.h>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <math.h>
#include <stack>
#include <string>
#include <assert.h>
#include <iomanip>
#include <iostream>
#include <sstream>
#define MINF 0x3f3f3f3f
using namespace std;
typedef long long LL;
const LL MOD = 20090717;
const int MAXN = 1e3+10; struct Node
{
int w, s;
int id;
bool operator < (const Node& that) const
{
return this->s > that.s;
}
}node[MAXN];
int Dp[MAXN], Pre[MAXN];
int n; void Print(int p)
{
if (p == -1)
return;
Print(Pre[p]);
printf("%d\n", node[p].id);
} int main()
{
int l, r;
while (~scanf("%d%d", &l, &r))
{
node[++n].w = l;
node[n].s = r;
node[n].id = n;
}
sort(node+1, node+1+n);
memset(Pre, -1, sizeof(Pre));
memset(Dp, 0, sizeof(Dp));
for (int i = 1;i <= n;i++)
{
Dp[i] = 1;
for (int j = 1;j < i;j++)
{
if (node[i].w > node[j].w && node[i].s < node[j].s)
{
if (Dp[j]+1 > Dp[i])
{
Dp[i] = Dp[j]+1;
Pre[i] = j;
}
}
}
}
int maxval = 1, maxpos = 1;
for (int i = 1;i <= n;i++)
{
if (maxval < Dp[i])
{
maxval = Dp[i];
maxpos = i;
}
}
printf("%d\n", maxval);
Print(maxpos); return 0;
}

HDU-1160-FatMouse's Speed(DP, 最长递增子序列)的更多相关文章

  1. HDU 1160 FatMouse's Speed (DP)

    FatMouse's Speed Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Su ...

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

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

  3. [DP]最长递增子序列

    #include <iostream> #include <limits.h> #include <vector> #include <algorithm&g ...

  4. poj 1631 Bridging signals (二分||DP||最长递增子序列)

    Bridging signals Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9234   Accepted: 5037 ...

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

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

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

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

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

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

  8. HDU 1160 FatMouse's Speed(DP)

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

  9. HDU 1160 FatMouse's Speed (最长上升子序列)

    题目链接 题意:n个老鼠有各自的重量和速度,要求输出最长的重量依次严格递增,速度依次严格递减的序列,n最多1000,重量速度1-10000. 题解:按照重量递增排序,找出最长的速度下降子序列,记录序列 ...

随机推荐

  1. Windows下jmap命令报错问题

       最近换了笔记本,新的工作环境下jmap命令居然在报错,而jps.jstat.jinfo.jstack都能正常使用,所以初步排除进程号的问题. Attaching to core 17536 fr ...

  2. 【计算几何】Water Testing

    Water Testing 题目描述 You just bought a large piece of agricultural land, but you noticed that – accord ...

  3. MySQL 子查询(三) 派生表、子查询错误

    From MySQL 5.7 ref:13.2.10.8 Derived Tables 八.派生表 派生表是一个表达式,用于在一个查询的FROM子句的范围内生成表. 例如,在一个SELECT查询的FR ...

  4. 整理下线段树吧 poj hotel

    除了上次的新学的有 区间更新 延迟更新  区间合并 先说下区间更新以及延迟更新吧 既然是对区间的维护 在求解一些问题的时候 有的时候没有必要对所有的自区间都进行遍历 这个时候 延迟标记就派上用场了 ( ...

  5. vs2019 扩展工具

    这里只是做个记录,没啥技术含量 本人代码上有些强迫症,所以我的本地代码一定不可以丢,之前用vs2013开始,就安装了localhistory这个插件,十分方便,觉得不用了,清了即可,也不占地方. 但是 ...

  6. docker系列之六容器数据卷

    docker之容器数据卷 一.容器数据卷 docker容器运行的时候,会产生一系列的文件,那么我们希望容器产生的数据能提供给其他的容器使用,也就是说怎么实现容器间的数据的共享呢?这就需要用到我们所提到 ...

  7. JS中this和call

    首先来了解一下JS中this的原理: 要访问自己的属性就必须使用 this.属性名 1.this总是指向它的直接调用者: var a={ user:'Artimis', fn:function(){ ...

  8. linux服务脚本

    #!/bin/sh ARG=$1 case $ARG in start): nohup /path/program & ;; stop): pkill program ;; restart): ...

  9. 软件打包 Inno

    官网 http://www.jrsoftware.org/ 新建 点击工具栏第一项"新建".输入产品的名称.版本号.公司网址等信息 添加应用程序文件 应用程序图标 应用程序文档 许 ...

  10. TreeMap核心源码实现解析

    TreeMap实现了SotredMap接口,它是有序的集合.而且是一个红黑树结构,每个key-value都作为一个红黑树的节点.如果在调用TreeMap的构造函数时没有指定比较器,则根据key执行自然 ...