动态规划的解决方法是找到动态转移方程。

题目地址:http://acm.hdu.edu.cn/game/entry/problem/show.php?chapterid=3&sectionid=2&problemid=4

题目大意:找到一个最多的老鼠序列,使得序列中的老鼠的体重满足递增,相应老鼠的速度满足递 减。即可要求找出老鼠体重递增,速度递减的最长子序列(不需要连续).

思路:动态转移方程的确定,状态f[i]表示前i个老鼠中的最长递减子序列长度,状态转移方程为mouse[i].len = max{mouse[i].len, mouse[j].speed > mouse[i].speed} + 1, 最后找出最大的f[i]即可。

注意:此题还需要输出找到的序列中的老鼠的最原始的标号,因此不仅要在刚开始的时候把每个老鼠的最初的序号记下来,还要在进行 状态转移的时候把当前的老鼠的位置标记下来。

 #include <iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define Maxn 10010
using namespace std; struct node{
int id;
int weight;
int speed;
int pre;
int len ;
}mouse[Maxn]; int cmp(const struct node &a,const struct node &b)
{
if(a.weight!=b.weight)
return a.weight<b.weight;
return a.speed<b.speed; } void output(int k)
{
if(mouse[k].len==)
printf("%d\n",mouse[k].id);
else
{
output(mouse[k].pre);
printf("%d\n",mouse[k].id);
}
} int main()
{
int cnt=;
while(scanf("%d%d",&mouse[cnt].weight,&mouse[cnt].speed))
{
mouse[cnt].id=cnt+;
mouse[cnt].len=;
cnt++;
}
sort(mouse,mouse+cnt,cmp);
int i,j;
for(i=;i<cnt;i++)
for(j=;j<i;j++)
{
if(mouse[i].weight>mouse[j].weight&&mouse[i].speed<mouse[j].speed)//状态转移方程使用
if(mouse[i].len<mouse[j].len+)
{
mouse[i].len=mouse[j].len+;
mouse[i].pre=j;
}
} int num=;
for(i=;i<cnt;i++)
if(mouse[num].len<mouse[i].len)
num=i;//记录下表
printf("%d\n",mouse[num].len);
output(num);
return ; }

hdu FatMouse's Speed 动态规划DP的更多相关文章

  1. HDU FatMouse's Speed 基本DP

    题意:要求找到的体重递增,速度递减的老鼠,并且输出最长的长度数,而且输出各自的序列数.Special Judge 思路:先按体重由小到大排序,再找最长速度递减序列. 转移方程:mou[i].w> ...

  2. FatMouse's Speed 基础DP

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

  3. zoj 1108 FatMouse's Speed 基础dp

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

  4. zoj 1108 FatMouse's Speed 基础dp

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

  5. hdoj1160 FatMouse's Speed 动态规划

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

  6. HDU 1160 FatMouse's Speed LIS DP

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

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

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

  8. HDU 1160 FatMouse's Speed(DP)

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

  9. HDU - 1160 FatMouse's Speed 【DP】

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1160 题意 给出一系列的 wi si 要找出一个最长的子序列 满足 wi 是按照升序排列的 si 是按 ...

随机推荐

  1. css技巧

    1.实现position为fixed与absolute值时居中定位: 给需要定位的元素块外加一层div盒子,外层div盒子存在于文档流中,让外层div盒子居中定位并设置position属性为relat ...

  2. USACO翻译:USACO 2012 JAN三题(3)

    USACO 2012JAN(题目三) 一.题目概览 中文题目名称 放牧 登山 奶牛排队 英文题目名称 grazing climb lineup 可执行文件名 grazing climb lineup ...

  3. Java程序开发.邱加永2.1节

    by2016.9.8 2.7.1 一维数组 1. 声明 int[] m: char[] c: double[] d:   2. 创建 数组声明之后还不能使用,m = new int[10]: c = ...

  4. CSS基础篇之背景、过渡动画

    background-origin(背景原点) 设置元素背景图片的原始起始位置.必须保证背景是background-repeat为no-repeat属性才能生效. background-origin: ...

  5. 第一篇博客 用笨办法学python-14 提示和传递

    # 代码如下: usr_name = input("")script = input("")prompt = '> 'print("hi %s, ...

  6. c#多线程介绍(上)

    转载原文:这里是链接内容 转载原文:这里写链接内容 转载原文:这里写链接内容 (重要事情说三遍) 引言 本文主要从线程的基础用法,CLR线程池当中工作者线程与I/O线程的开发,并行操作PLINQ等多个 ...

  7. 关于MongoDB你需要知道的几件事

    Henrique Lobo Weissmann是一位来自于巴西的软件开发者,他是itexto公司的联合创始人,这是一家咨询公司.近日,Henrique在博客上撰文谈到了关于MongoDB的一些内容,其 ...

  8. ABP理论学习之内嵌资源文件

    返回总目录 本篇目录 介绍 创建内嵌文件 暴露内嵌文件 使用内嵌文件 介绍 在一个web应用中,有供客户端使用的javascript,css,xml等文件.它们一般是作为分离的文件被添加到web项目中 ...

  9. Java Collections.sort方法对list集合排序

    1.排序测试类 package com.ljq.test; import java.util.ArrayList; import java.util.Collections; import java. ...

  10. How.To.Process.Image.Infomation.Of.Rotate.And.Flip.From.Server

    需求说明 客户端接收到服务器传送过来的图像数据,客户端通过对图像进行旋转和反转操作. 然后把这个旋转和反转的数据上传到服务器. 客户端在接收图像的时候, 也会下载以前的旋转和反转参数, 然后客户端根据 ...