链接:

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. Redis SETNX实现分布式锁

    1.某进程1执行 SETNX lock 以尝试获取锁 2.由于某进程2已获得了锁,所以进程1执行 SETNX lock 返回0,即获取锁失败 3.进程1执行 GET lock 来检测锁是否已超时,如果 ...

  2. List 报错 java.lang.UnsupportedOperationException

    废话不多说,上代码 public class ArrayListTest { @Test public void testList() { List<Long> longList = ne ...

  3. 【转载】spring mvc 后端获得前端传递过来的参数的方法

    1.通过HttpServletRequest 获得 HttpServletRequest.getParameter(参数名),可以获得form表单中传递的参数,或ajax或url中传递过来的参数,如果 ...

  4. WUSTOJ 1241: 到底是几月几日?(Java)

    1241: 到底是几月几日? 题目   输入年月日,输出当前日期是当年的第几天,输入年份和第几天,输出当前日期.更多内容点击标题. 说明   算是水题吧,仅提供代码做参考,不做分析.代码没用JDK自带 ...

  5. ARTS

    ARTS的初衷 Algorithm.主要是为了编程训练和学习.每周至少做一个 leetcode 的算法题(先从Easy开始,然后再Medium,最后才Hard).进行编程训练,如果不训练你看再多的算法 ...

  6. STM32启动文件详解

    启动文件使用的 ARM 汇编指令汇总 启动程序源码注释(点此下载) 1. Stack—栈 Stack_Size EQU 0x00000400 AREA STACK, NOINIT, READWRITE ...

  7. scratch少儿编程——03、动作:运动的开始,游戏的基础。

    各位小伙伴大家好: 从这一期开始我们来学Scratch的具体操作. 第一季我们会从每一个脚本模块开始.一个程序块一个程序块去操作,感受它的效果. 今天我们来一起学习程序区的脚本类动作模块的指令. 动作 ...

  8. Scratch:海龟绘图(九)

    在本课的前导部分,我们说到怎么做才能成为一个负责任的“程序猿”.我认为,负责任的程序员决不会草率的处理任何“函数接口”. 比如这个“画圆”函数,程序员就会认真推敲“哪些参数是必要的.哪些参数又是多余的 ...

  9. C#获取ip

    string name = Dns.GetHostName(); string ip = Dns.GetHostAddresses(name).First().ToString();

  10. python处理RSTP视频流

    python链接海康摄像头,并以弹出框的方式播放实时视频流, 这种方式是以弹出框的形式播放.本地测试可以,实际业务场景不建议使用.可以采用rtsp转rtmp的方式 @shared_task def p ...