题目链接

http://acm.hdu.edu.cn/showproblem.php?pid=1160

题意

给出一系列的 wi si

要找出一个最长的子序列 满足

wi 是按照升序排列的

si 是按照 降序排列的

思路

因为有双关键词

我们 可以先将一关键词 比如 W 按照 升序排序

再根据 S 关键词 来找 最长下降子序列 就可以了

要输出 其中的一个子序列 我们只要 记录 其 父节点就可以

再循环网上找

AC代码

#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <stack>
#include <set>
#include <list>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <limits> #define CLR(a, b) memset(a, (b), sizeof(a))
#define pb push_back using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair<string, int> psi;
typedef pair<string, string> pss; const double PI = acos(-1.0);
const double E = exp(1.0);
const double eps = 1e-8; const int INF = 0x3f3f3f3f;
const int maxn = 1e3 + 5;
const int MOD = 1e9 + 7; struct node
{
int w, s;
int id;
}q[maxn]; bool comp(node x, node y)
{
if(x.w == y.w)
return x.s > y.s;
return x.w < y.w;
} int dp[maxn];
int pre[maxn]; int main()
{
int pos = 1;
while (~scanf("%d%d", &q[pos].w, &q[pos].s))
q[pos].id = pos++;
sort(q, q + pos, comp);
int ans = 1;
CLR(dp, 0);
CLR(pre, 0);
for (int i = 1; i <= pos; i++)
{
dp[i] = 1;
for (int j = 1; j < i; j++)
{
if (q[i].s < q[j].s && q[i].w > q[j].w)
{
if (dp[j] + 1 > dp[i])
{
dp[i] = dp[j] + 1;
pre[i] = j;
}
}
}
ans = max(ans, dp[i]);
}
printf("%d\n", ans);
vector <int> v;
for (int i = 1; i <= pos; i++)
{
if (dp[i] == ans)
{
int vis = i;
v.pb(q[vis].id);
while (pre[vis])
{
v.pb(q[pre[vis]].id);
vis = pre[vis];
}
break;
}
}
vector <int>::iterator it;
for (it = v.end(), it--; ; it--)
{
printf("%d\n", *it);
if (it == v.begin())
break;
}
}

HDU - 1160 FatMouse's Speed 【DP】的更多相关文章

  1. HDU 1160 FatMouse's Speed LIS DP

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

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

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

  3. HDU 1160 FatMouse's Speed(DP)

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

  4. hdu 1078 FatMouse and Cheese【dp】

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1078 题意:每次仅仅能走 横着或竖着的 1~k 个格子.求最多能吃到的奶酪. 代码: #include ...

  5. HDU 1160 FatMouse's Speed ——(DP)

    又是那个lis变形的题目. 但是不好定义严格的比较符号,因此只能n^2去做.值得注意的一个是要先排序,因为可能可以先选后面的再选前面的,先排序的话就能够避免这个问题.但是要注意,因为要输出路径,所以要 ...

  6. 【最长上升子序列记录路径(n^2)】HDU 1160 FatMouse's Speed

    https://vjudge.net/contest/68966#problem/J [Accepted] #include<iostream> #include<cstdio> ...

  7. HDU 1160 FatMouse's Speed (DP)

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

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

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

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

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

随机推荐

  1. 【spring boot】11.spring-data-jpa的详细介绍和复杂使用

    ==================================================================================================== ...

  2. SVN merge 三种方式

    1.Merge a range of revisions 2.Reintegrate a branch 3.Merge two different trees ———————————————————— ...

  3. Cookie常用方法封装Utils

    1.查询某个指定的cookie package com.sun.etalk.cookie; import javax.servlet.http.Cookie; public class CookieU ...

  4. TCP/IP详解 卷一(第六章 ICMP:Internet控制报文协议)

    ICMP是(Internet Control Message Protocol)Internet控制报文协议. 用于在IP主机.路由器之间传递控制消息.控制消息是指网络通不通.主机是否可达.路由是否可 ...

  5. struts2获取前台提交的参数

      CreateTime--2017年8月25日16:30:11 Author:Marydon struts2对获取前台提交参数的封装 需要导入: import java.util.Enumerati ...

  6. NodeJS 安装cnpm命令行工具

    在安装之前,请确保已安装Git和NodeJS. cmd机内命令窗口,输入以下命令: git config --system http.sslcainfo /bin/curl-ca-bundle.crt ...

  7. 如何用openssl命令行生成证书

    老大要我在web server里面加上https功能,可是但就使用openssl生成证书就耗费了我两天时间,网上有很多相关的资料,但是都写的很复杂, 照着他们的来,还是走了很多弯路. 我总结一下,步骤 ...

  8. FullPage.js 活动单页 - 全屏滚动插件

    插件描述:fullPage.js 是一个基于 jQuery 的插件,它能够很方便.很轻松的制作出全屏网站. https://www.uedsc.com/fullpage.html 官网 如今我们经常能 ...

  9. NativeBase准备工作

    环境 node>= 4.0 npm>= 3.0 rnpm (only if React Native version < 0.29) ReactNativeCLI  安装及运行 ht ...

  10. SkipList跳跃表(Java实现)

    取自网络https://github.com/spratt/SkipList AbstractSortedSet.java package skiplist_m; /***************** ...