本题大意:给定一定数量的数对,每个数保存着一只老鼠的质量和速度,让你求出一个最长序列,这个序列按照质量严格递增,速度严格递减排列,让你输出这个序列的最长长度,并且输出组成这个最长长度的序列的对应的老鼠的编号...

  本题思路:看到最长序列,可以想到是LIS的变形,然后需要打印路径,那我们只需要回溯思想数组保存即可。很基础的一道题目......记得找到最后的那只老鼠...

  参考代码:

 #include <iostream>
#include <cstring>
#include <algorithm>
#include <stack>
using namespace std; const int maxn = 1e3 + ;
struct node {
int m, s, pre, ind;
} a[maxn]; bool cmp(const node a, const node b) {
if(a.m == b.m) return a.s > b.s;
return a.m < b.m;
} bool check(int i, int j) {
return a[i].m > a[j].m && a[i].s < a[j].s;
} int main () {
int num = , c1, c2, cnt = , ans = , preidx = , dp[maxn];
memset(dp, , sizeof dp);
while(cin >> c1 >> c2) {
a[++ num].m = c1;
a[num].s = c2;
a[num].ind = num;
a[num].pre = -;
}
sort(a + , a + num + , cmp);
for(int i = ; i <= num; i ++) {
dp[i] = ;
for(int j = ; j < i; j ++) {
if(check(i, j) && dp[i] < dp[j] + ) {
dp[i] = dp[j] + ;
a[i].pre = j;
}
if(dp[i] > ans) {
preidx = i;
ans = dp[i];
}
}
}
cout << ans << endl;
stack <int >P;
while(preidx != - ) {
P.push(a[preidx].ind);
preidx = a[preidx].pre;
}
while(!P.empty()) {
cout << P.top() << endl;
P.pop();
}
return ;
}

  

HDU-1160.FatMouse'sSpeed.(LIS变形 + 路径打印)的更多相关文章

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

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

  2. HDU - 1160 FatMouse's Speed 动态规划LIS,路径还原与nlogn优化

    HDU - 1160 给一些老鼠的体重和速度 要求对老鼠进行重排列,并找出一个最长的子序列,体重严格递增,速度严格递减 并输出一种方案 原题等于定义一个偏序关系 $(a,b)<(c.d)$ 当且 ...

  3. HDU 1160 FatMouse's Speed (DP)

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

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

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

  5. hdu 1160 FatMouse's Speed (最长上升子序列+打印路径)

    Problem Description FatMouse believes that the fatter a mouse is, the faster it runs. To disprove 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 动态规划 记录路径的最长上升子序列变形

    题目大意:输入数据直到文件结束,每行两个数据 体重M 和 速度V,将其排列得到一个序列,要求为:体重越大 速度越低(相等则不符合条件).求这种序列最长的长度,并输出路径.答案不唯一,输出任意一种就好了 ...

  8. HDU 1160 FatMouse's Speed LIS DP

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

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

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

随机推荐

  1. LeetCode - Word Subsets

    We are given two arrays A and B of words. Each word is a string of lowercase letters. Now, say that ...

  2. 如何用node命令和webpack命令传递参数 转载

    1. 比如在项目中我们的publicPath需要根据服务器环境的变化而变化,这时我们会写一个配置文件,在webpack.config.js中读取,可以 如何才能 取到变量呢? 这里介绍一种方法: 如果 ...

  3. maven+dubbo+zookeeper 基础实例

    1.maven  引入依赖 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http:/ ...

  4. SpringBoot RestFul风格API接口开发

    本文介绍在使用springBoot如何进行Restful Api接口的开发及相关注解已经参数传递如何处理. 一.概念: REST全称是Representational State Transfer,中 ...

  5. NFC应用于公交卡

    NFC应用于公交卡https://www.cnblogs.com/liuzhaoyzz/p/7115098.html 带有NFC功能的安卓手机可以给实体公交卡充值,手机虚拟公交卡现在有两种方案,一种是 ...

  6. Python【每日一问】02

    问:列表 test = [1,2,3,1,3,4,5,67,7,8,54,1,2,3,4,5,6],如何删除该列表的重复元素? 方法1:利用集合的不重复性 # 利用集合的不重复性 test = [1, ...

  7. HTML---仿网易新闻登录页

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. android 开发 View _6_Canvas详解

    牛逼大神的博客地址:http://www.gcssloop.com/customview/Canvas_BasicGraphics 安卓自定义View进阶-Canvas之绘制图形 在上一篇自定义Vie ...

  9. Unable to complete the scan for annotations for web application [/wrs] due to a StackOverflowError. Possible root causes include a too low setting for -Xss and illegal cyclic inheritance dependencies.

    tomcat启动报错:Jul 20, 2018 11:48:37 AM org.apache.catalina.core.ContainerBase addChildInternalSEVERE: C ...

  10. py库: arrow (时间)

    arrow是个时间日期库,简洁易用.支持python3.6 https://arrow.readthedocs.io/en/latest/ arrow官网api https://github.com/ ...