题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1108

解题报告:

1、首先按照weight从小到大排列,weight相同的按照speed从大到小排列;

2、Count[i]表示到第i个老鼠时,所求的最长“速度递减”子序列的长度;

3、path[i]=j是题目的关键,记录在Count[i]=Count[j]时,即最长“速度递减”子序列最后一个老鼠的前一只老鼠的位置

4、递归输出id

void output(int path[],pos)
{
if(pos==) return ;
output(path,path[pos]);
printf("%d\n",mice[pos].id);
}

Sources Code:

#include <cstdio>
#include <stdlib.h>
#include <algorithm>
#define INF 0x3f3f3f3f using namespace std; int n;///n只老鼠
int Count[]= {}; ///count[i]表示构造到第i个老鼠时,序列的最大长度
int path[]= {}; ///path[i]表示构造到第i个老鼠时的前一个老鼠(前驱) struct mouse
{
int weight;
int speed;
int id;
} mice[]; int cmp(const void *a,const void *b)
{
struct mouse *p1=(mouse *)a;
struct mouse *p2=(mouse *)b;
if(p1->weight==p2->weight)
{
if(p1->speed>p2->speed)
return p2->speed-p1->speed;
else return p1->speed-p2->speed;
}
else return p1->weight-p2->weight;
} void output(int path[],int pos)
{
if(pos==) return ;
output(path,path[pos]);
printf("%d\n",mice[pos].id);
} int main()
{
n=;
int i=,j=;
while(scanf("%d%d",&mice[++i].weight,&mice[++j].speed)!=EOF)
{
n++;
mice[n].id=n;
}
qsort(mice+,n,sizeof(mice[]),cmp);
Count[]=;
for(int i=; i<=n; i++)
{
for(int j=; j<i; j++)
{
if(mice[i].weight>mice[j].weight&&mice[i].speed<mice[j].speed)
{
if(Count[i]<Count[j])
{
Count[i]=Count[j];
path[i]=j;
}
}
}
Count[i]++;
}
int _max=;
int pos;
for(int i=; i<=n; i++)
{
if(Count[i]>_max)
{
_max=Count[i];
pos=i;
}
}
printf("%d\n",_max);
output(path,pos);
}

动态规划(DP),类似LIS,FatMouse's Speed的更多相关文章

  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 (DP)

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

  3. FatMouse's Speed(HDU LIS)

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

  4. FatMouse's Speed 基础DP

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

  5. zoj 1108 FatMouse's Speed 基础dp

    FatMouse's Speed Time Limit: 2 Seconds      Memory Limit:65536 KB     Special Judge FatMouse believe ...

  6. HDU 1160:FatMouse's Speed(LIS+记录路径)

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

  7. zoj 1108 FatMouse's Speed 基础dp

    FatMouse's Speed Time Limit: 2 Seconds      Memory Limit:65536 KB     Special Judge FatMouse believe ...

  8. HDU-1160-FatMouse's Speed(线性DP,LIS)

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

  9. HDU1160 FatMouse's Speed —— DP

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1160 FatMouse's Speed Time Limit: 2000/1000 MS ...

随机推荐

  1. linux 重新定义命令alias——重定义查看日志命令

    背景:很多时候,需要输入一大串命令来查看日志,例如: cd /home/weblogic/prodmain/log/ftlog;tail -f tps-mv-ft-rolling.log 每次打开终端 ...

  2. app测试中,ios和android的区别

    App测试中ios和Android的区别: 1. Android长按home键呼出应用列表和切换应用,然后右滑则终止应用: 2. 多分辨率测试,Android端20多种,ios较少: 3. 手机操作系 ...

  3. 企业DevOps构建 (一)

    一,环境: tomcat 7.0.92 jenkins 1.658 maven mysql 5.5.23 mongodb 2.6.11 redis 4.0.12   01, 安装jenkins wge ...

  4. (转)python strip()函数 去空格\n\r\t函数的用法

    原文:http://www.cnblogs.com/zdz8207/p/python_learn_note_20.html python3.4学习笔记(二十) python strip()函数 去空格 ...

  5. java Folder transform to Source Folder

    右键文件夹然后选择Build Path ===>Use as Source Folder 里面的东西现在就可以编译了 然后想要让一个源码包变成一个文件夹的话: 只需要再次右键源码包==>选 ...

  6. TOJ 3486 Divisibility

    Description On the planet Zoop, numbers are represented in base 62, using the digits 0, 1, . . . , 9 ...

  7. linux_api之信号

    本片索引: 1.引言 2.信号 3.程序启动 4.signal函数 5.系统调用的中断和系统调用的重启(了解) 6.可再入与不可再入函数(了解) 7.kill函数和raise函数 8.alarm函数和 ...

  8. 1.3 js基础

    1.操作样式 .style  操作行间样式 .className  直接修改class   2.操作属性 .  操作已有的属性 []  点能做的方括号都能做,方括号里放字符串,能放变量.     3. ...

  9. [转]批处理for命令使用指南

    摘要:本文由浅入深,为大家专门讲解for的用法,希望大家喜欢. 首先应该明确的是,for不是一个简单的命令,它的用法比较复杂,它还可以带四个参数(/L /D /R /F),其中:/L和/F参数是最经常 ...

  10. 《Java开发实战经典》读书笔记

    Java常用的内存区域: (1)      栈内存空间:保存所有的对象名称. (2)      堆内存空间:保存每个对象的具体属性内容. (3)      全局数据区:保存static类型的属性. ( ...