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

题目地址: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. bzoj3380+3381+3382+3383 Usaco2004 Open

    四道比较水的题 T1:SPFA+状压 #include<stdio.h> #include<string.h> #include<algorithm> #inclu ...

  2. 一些值得练习的github项目

    简单粗暴,一晚上用 node.Vue 写个联机五子棋 https://github.com/ccforward/cc/issues/51 Vue2.0实现简易豆瓣电影webApp https://gi ...

  3. Collections+Iterator 接口 | Map+HashMap+HashTable+TreeMap |

    Collections+Iterator 接口 1. Collections 是一个操作 Set.List 和 Map 等集合的工具类 Collections 中提供了大量方法对集合元素进行排序.查询 ...

  4. 字典NSDictionary以及NSMutableDictionary的用法总结

    做过Java语言 或者 C语言 开发的朋友应该很清楚 关键字map 吧,它可以将数据以键值对儿的形式储存起来,取值的时候通过KEY就可以直接拿到对应的值,非常方便.在Objective-C语言中 词典 ...

  5. RecylerView完美实现瀑布流效果

    RecylerView包含三种布局管理器,分别是LinearLayoutManager,GridLayoutManager,StaggeredGridLayoutManager,对应实现单行列表,多行 ...

  6. 安卓动态调试七种武器之长生剑 - Smali Instrumentation

    安卓动态调试七种武器之长生剑 - Smali Instrumentation 作者:蒸米@阿里聚安全 0x00 序 随着移动安全越来越火,各种调试工具也都层出不穷,但因为环境和需求的不同,并没有工具是 ...

  7. 解读2015年互联网UGC内容发展态势,安全事件频发

    <2015内容安全年报> 阿里移动安全 第一章 2015年内容安全形势 随着互联网业务的迅速发展,互联网上的信息内容带来了爆炸式的增长.由于缺乏对网络活动进行有效监督和管理的措施,致使互联 ...

  8. 【完全开源】百度地图Web service API C#.NET版,带地图显示控件、导航控件、POI查找控件

    目录 概述 功能 如何使用 参考帮助 概述 源代码主要包含三个项目,BMap.NET.BMap.NET.WindowsForm以及BMap.NET.WinformDemo. BMap.NET 对百度地 ...

  9. WCF学习之旅—WCF第二个示例(六)

    第五步,创建数据服务 在“解决方案资源管理器”中,使用鼠标左键选中“SCF.WcfService”项目,然后在菜单栏上,依次选择“项目”.“添加新项”. 在“添加新项”对话框中,选择“Web”节点,然 ...

  10. Design7:数据删除设计

    在设计一个新系统的Table Schema的时候,不仅需要满足业务逻辑的复杂需求,而且需要考虑如何设计schema才能更快的更新和查询数据,减少维护成本. 模拟一个场景,有如下Table Schema ...