题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1160

题意就是给你一些老鼠(编号1,2,3,4,5,6,7,8...)的体重和他们的速度然后求出最大的n满足

W[m[1]] < W[m[2]] < ... < W[m[n]]

and

S[m[1]] > S[m[2]] > ... > S[m[n]]

然后把原来的编号按照上面的序列输出来;

先把他们排序一下dp的时候记录一下路径;

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
using namespace std;
#define N 1550
#define INF 0xffffff
struct node
{
int w, s, id;
}a[N];
int cmp(node p, node q)
{
if(p.w!=q.w)
return p.w<q.w;
return p.s>q.s;
}
int main()
{
int n=, dp[N], pre[N];
///freopen("in.txt", "r", stdin);
while(scanf("%d%d", &a[n].w, &a[n].s)!=EOF)
{
a[n].id=n+;
n++;
}
sort(a, a+n, cmp);
memset(dp, , sizeof(dp));
memset(pre, -, sizeof(pre));
int Max = ;
int Index = -;
for(int i=; i<n; i++)
{
dp[i]=;
for(int j=; j<i; j++)
{
if(a[j].w<a[i].w && a[j].s>a[i].s)
{
if(dp[j]+>dp[i])
{
dp[i]=dp[j]+;
pre[i]=j;
}
}
}
if(Max<dp[i])
{
Max = dp[i];
Index = i;
}
}
printf("%d\n", Max);
int b[N]={},k=;
for(int i=Index; i!=-; i=pre[i])
{
b[k++]=a[i].id;
}
for(int i=k-; i>=; i--)
printf("%d\n", b[i]);
return ;
}

FatMouse's Speed---hdu1160(简单dp)的更多相关文章

  1. hdu1160简单dp最长下降子序列

    /* 简单dp,要记录顺序 解:先排序,然后是一个最长下降子序列 ,中间需记录顺序 dp[i]=Max(dp[i],dp[j]+1); */ #include<stdio.h> #incl ...

  2. FatMouse's Speed ~(基础DP)打印路径的上升子序列

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

  3. ZOJ 1108 FatMouse's Speed (HDU 1160) DP

    传送门: ZOJ:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=108 HDU :http://acm.hdu.edu.cn/s ...

  4. HDU1160 FatMouse's Speed —— DP

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

  5. HDU 1160 FatMouse's Speed (DP)

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

  6. FatMouse's Speed 基础DP

    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. zoj 1108 FatMouse's Speed 基础dp

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

  9. FatMouse's Speed

    J - FatMouse's Speed DP的题写得多了慢慢也有了思路,虽然也还只是很简单的DP. 因为需要输出所有选择的老鼠,所以刚开始的时候想利用状态压缩来储存所选择的老鼠,后面才发现n太大1& ...

随机推荐

  1. THINKPHP3.2视频教程

    http://edu.51cto.com/lesson/id-24504.html lunix视频教程 http://bbs.lampbrother.net/read-htm-tid-161465.h ...

  2. file's owner以及outlet与连线的理解

    转自:http://www.cnblogs.com/martin1009/archive/2012/06/01/2531028.html xib文件本身可以看做是一个xml,app启动的时候会根据xm ...

  3. WCF问题集锦:未依照DataMember定义的名称序列化对象

    今遇到WCF序列化BUG,代码例如以下: /// <summary> /// 包括数据的返回对象 /// </summary> /// <typeparam name=& ...

  4. java中调用数据库中的存储过程和函数

    public static void main(String[] args)    {         Connection conn =getConnection(url,user, pwd);   ...

  5. redis源码学习_简单动态字符串

    SDS相比传统C语言的字符串有以下好处: (1)空间预分配和惰性释放,这就可以减少内存重新分配的次数 (2)O(1)的时间复杂度获取字符串的长度 (3)二进制安全 主要总结一下sds.c和sds.h中 ...

  6. 使用thrift进行跨语言调用(php c# java)

    使用thrift进行跨语言调用(php c# java)   1:前言 实际上本文说的是跨进程的异构语言调用,举个简单的例子就是利用PHP写的代码去调C#或是java写的服务端.其实除了本文提供的办法 ...

  7. linux设置时间的方法

    0. date -R  中国上海的时区是+8000 1.tzselect 设置时区,依次选择5,9,1,1(如果时区不一样,执行下面的命令得到之后时间是不一样的) 2.sudo ntpdate asi ...

  8. Ubuntu 12.04下PostgreSQL-9.1安装与配置详解(在线安装) [转]

    说明:       我是用root用户在终端登陆的,如果是非root用户,那在命令前需要加上"sudo",你懂的... 第一步:在Ubuntu下安装Postgresql       ...

  9. MapReduce实战(五)实现关联查询

    需求: 利用MapReduce程序,实现SQL语句中的join关联查询. 订单数据表order: id date pid amount 1001 20150710 P0001 2 1002 20150 ...

  10. [Tips]Javascrip计算文件行数

    function calcLineCount(filename, callback) { var fs = require('fs'); var fileStream = fs.createReadS ...