链接:

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. [转帖]MMU内存管理单元

    MMU内存管理单元 https://www.cnblogs.com/alantu2018/p/9002309.html 之前对这一块一直不理解 最近学习了点 CPU time slice 以及 con ...

  2. 从 select ... for update来分析mysql的锁

    一 mysql的悲观锁 - 以行锁做示例 每次拿数据的时候都认为别的线程会修改数据,所以每次拿数据的时候都会给数据上锁.上锁之后,当别的线程想要拿数据时,就会阻塞.直到给数据上锁的线程将事务提交或者回 ...

  3. CSP-S初赛

    初赛都过了好几天了,现在才想起来写点关于初赛的博客也真是...... 我是福建人,是在福建的赛点参加的CSP-S组的初赛,能力其实很弱,估分只能60多一点点.真是害怕一不小心这篇博客就变成了我的退役博 ...

  4. python学习-47 random模块

    random模块 随机模块 random 的方法: print(random.random()) # [0,1] 的浮点数 print(random.randint(1,3)) print(rando ...

  5. python reportlab 生成table

    ''' Table(data, colWidths=None, rowHeights=None, style=None, splitByRow=, repeatRows=, repeatCols=, ...

  6. PAT(B) 1013 数素数(Java)

    题目链接:1013 数素数 代码 /** * Score: 20 * Run Time: 124ms * @author wowpH * @version 1.0 */ import java.uti ...

  7. oj上的测试点信息

    Accepted                          通过!(AC) Wrong Answer                  答案错.(WA) Runtime Error      ...

  8. css 样式合集

    td换行: style="word-wrap:break-word;word-break:break-all;" 超长省略号: table { table-layout: fixe ...

  9. uboot 与 代码重定位

    ref: https://blog.csdn.net/dhauwd/article/details/78566668 https://blog.csdn.net/yueqian_scut/articl ...

  10. 无法访问VMWARE虚拟机中linux的nginx地址

    取得root权限,然后在centos(6.5)中关闭防火墙: service iptables stop 关闭后在windows 10 中浏览器通过虚拟机的ip地址可以直接访问了. 经过测试,打开ip ...