HDU 1160 FatMouse's Speed(DP)
题意 输入n个老鼠的体重和速度 从里面找出最长的序列 是的重量递增时速度递减
简单的DP 令d[i]表示以第i个老鼠为所求序列最后一个时序列的长度 对与每一个老鼠i 遍历全部老鼠j 当(w[i] > w[j]) && (s[i] < s[j])时 有d[i]=max(d[i],d[j]+1) 输出路径记下最后一个递归即可了
#include<cstdio>
#include<algorithm>
using namespace std;
const int M=1005;
int w[M], s[M], d[M], pre[M], n, key; int dp (int i)
{
if (d[i] > 0) return d[i];
for (int j = d[i] = 1; j <= n; ++j)
if ( (w[i] > w[j]) && (s[i] < s[j]) && (d[i] < dp (j) + 1))
d[i] = d[j] + 1, pre[i] = j;
return d[i];
} void print (int i)
{
if (pre[i])
print (pre[i]);
printf ("%d\n", i);
} int main()
{
n = 0;
while (scanf ("%d %d", &w[n], &s[++n]) != EOF);
for (int i = key =1; i <= n; ++i)
if (dp (i) > dp (key)) key = i;
printf ("%d\n", d[key]);
print (key);
return 0;
}
FatMouse's Speed
of mice and put as large a subset of this data as possible into a sequence so that the weights are increasing, but the speeds are decreasing.
The data for a particular mouse will consist of a pair of integers: the first representing its size in grams and the second representing its speed in centimeters per second. Both integers are between 1 and 10000. The data in each test case will contain information
for at most 1000 mice.
Two mice may have the same weight, the same speed, or even the same weight and speed.
each contain a single positive integer (each one representing a mouse). If these n integers are m[1], m[2],..., m[n] then it must be the case that
W[m[1]] < W[m[2]] < ... < W[m[n]]
and
S[m[1]] > S[m[2]] > ... > S[m[n]]
In order for the answer to be correct, n should be as large as possible.
All inequalities are strict: weights must be strictly increasing, and speeds must be strictly decreasing. There may be many correct outputs for a given input, your program only needs to find one.
6008 1300
6000 2100
500 2000
1000 4000
1100 3000
6000 2000
8000 1400
6000 1200
2000 1900
4
4
5
9
7
HDU 1160 FatMouse's Speed(DP)的更多相关文章
- HDU 1160 FatMouse's Speed DP题解
本题就先排序老鼠的重量,然后查找老鼠的速度的最长递增子序列,只是由于须要按原来的标号输出,故此须要使用struct把三个信息打包起来. 查找最长递增子序列使用动态规划法.主要的一维动态规划法了. 记录 ...
- HDU 1160 FatMouse's Speed (最长有序的上升子序列)
题意:给你一系列个w,s.要你找到最长的n使得 W[m[1]] < W[m[2]] < ... < W[m[n]] and S[m[1]] > S[m[2]] > ... ...
- HDU 1160 FatMouse's Speed (DP)
FatMouse's Speed Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Su ...
- HDU 1160 FatMouse's Speed(DP)
点我看题目 题意 :给你好多只老鼠的体重和速度,第 i 行代表着第 i 个位置上的老鼠,让你找出体重越大速度越慢的老鼠,先输出个数,再输出位置. 思路 :看题的时候竟然脑子抽风了,看了好久愣是没明白题 ...
- HDU 1160 FatMouse's Speed(要记录路径的二维LIS)
FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU - 1160 FatMouse's Speed 动态规划LIS,路径还原与nlogn优化
HDU - 1160 给一些老鼠的体重和速度 要求对老鼠进行重排列,并找出一个最长的子序列,体重严格递增,速度严格递减 并输出一种方案 原题等于定义一个偏序关系 $(a,b)<(c.d)$ 当且 ...
- HDU 1160 FatMouse's Speed (最长上升子序列)
题目链接 题意:n个老鼠有各自的重量和速度,要求输出最长的重量依次严格递增,速度依次严格递减的序列,n最多1000,重量速度1-10000. 题解:按照重量递增排序,找出最长的速度下降子序列,记录序列 ...
- HDU 1160 FatMouse's Speed LIS DP
http://acm.hdu.edu.cn/showproblem.php?pid=1160 同样是先按它的体重由小到大排,相同就按speed排就行. 这样做的好处是,能用O(n^2)枚举,因为前面的 ...
- HDU 1160 FatMouse's Speed (sort + dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1160 给你一些老鼠的体重和速度,问你最多需要几只可以证明体重越重速度越慢,并输出任意一组答案. 结构体 ...
随机推荐
- [Usaco2009 Nov]lights
题目描述: 给出$n$,$m$,表示有$n$盏灯和$m$条奇怪的电线,按下电线一段的灯后另一端会有影响. 求最少按几次. 题解: 高消解异或方程组,得到一堆自由元后搜索自由元状态,然后不断更新答案. ...
- layui使用小记(持续更新)
关于Select等Form表单元素,在使用的时候部分特性会失效 如select自带的Search功能: 其实在使用Form表单元素的时候,你如果需要layui自带的一些功能(搜索,验证等),请用< ...
- 如何使用GoEasy实现PHP与Websocket实时通信
最近搞了搞websocket 做了个简答的聊天demo 1. 从GoEasy获取appkey appkey是验证用户的有效性的唯一标识. Ø 注册账号. GoEasy官网:https:// ...
- docker 阿里云镜像加速器
传送门:阿里云镜像地址 Ubuntu/CentOS 安装/升级你的Docker客户端 推荐安装1..0以上版本的Docker客户端,参考文档 docker-ce 如何配置镜像加速器 针对Docker客 ...
- 条款28:避免返回handles指向对象内部的成分(Avoid returning "handles" to objects internals)
NOTE: 1.避免返回handles(包括references 指针 迭代器)指向对象内部.遵守这个条款可增加分装性,帮助const 成员函数的行为像个const,并将发生“虚吊号码牌”(dangl ...
- 第五章:C++程序的结构
主要内容: 1.作用域与可见性 2.对象的生存期 3.数据与函数 4.静态成员 5.共享数据的保护 6.友元 7.编译预处理命令 8.多文件结构和工程 作用域:函数原型作用域.块作用域.类作用域.文件 ...
- Mysql 锁总结
锁 部分总结参考博客 http://b.codejs.cc/articles/2017/10/23/1508749325215.html http://blog.csdn.net/cug_jiang1 ...
- python书籍推荐:量化投资:以Python为工具
所属网站分类: 资源下载 > python电子书 作者:mimi 链接:http://www.pythonheidong.com/blog/article/451/ 来源:python黑洞网 内 ...
- 【HDU 6000】Wash(贪心)
Problem Description Mr.Panda is about to engage in his favourite activity doing laundry! He's brough ...
- 深刻理解下js的prototype
参考 http://aralejs.org/class/docs/competitors.html, http://www.iteye.com/topic/248933,http://www.cnbl ...