HDU 1160 FatMouse's Speed(DP)
题意 :给你好多只老鼠的体重和速度,第 i 行代表着第 i 个位置上的老鼠,让你找出体重越大速度越慢的老鼠,先输出个数,再输出位置。
思路 :看题的时候竟然脑子抽风了,看了好久愣是没明白题目是什么意思。其实就是先按照体重排序,然后在速度里边找最长下降子序列,记录一下他们原来的位置,输出就行。数组开小了还WA了一次
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <stack> using namespace std ; struct node
{
int weight ;
int speed ;
int position ;
}map[] ; int pre[] ;
int dp[] ; bool cmp(const node a,const node b)
{
if(a.weight == b.weight) return a.speed > b.speed ;
return a.weight < b.weight ;
} int main()
{
int i = ;
while(scanf("%d %d",&map[i].weight,&map[i].speed) != EOF)
{
map[i].position = i ;
i++ ;
}
sort(map+,map+i,cmp) ;
pre[] = ;
dp[] = ;
stack<int>Q ;
for(int j = ; j < i ; j++)
{
int t = ;
for(int k = ; k < j ; k++)
{
if(map[k].weight < map[j].weight && map[k].speed > map[j].speed && dp[k] > t)
{
t = dp[j] ;
pre[j] = k ;
}
dp[j] = t+ ;
}
}
int maxx = -,maxn ;
for(int j = ; j < i ; j++)
{
if(dp[j] > maxx)
{
maxx = dp[j] ;
maxn = j ;
}
}
printf("%d\n",maxx) ;
int n = maxx ;
while(maxx--)
{
int t = maxn ;
Q.push(map[t].position) ;
maxn = pre[t] ;
}
while(n--)
{
printf("%d\n",Q.top()) ;
Q.pop() ;
}
return ;
}
HDU 1160 FatMouse's Speed(DP)的更多相关文章
- HDU 1160 FatMouse's Speed ——(DP)
又是那个lis变形的题目. 但是不好定义严格的比较符号,因此只能n^2去做.值得注意的一个是要先排序,因为可能可以先选后面的再选前面的,先排序的话就能够避免这个问题.但是要注意,因为要输出路径,所以要 ...
- 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 (动态规划、最长下降子序列)
FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- hdu 1160 FatMouse's Speed(最长不下降子序列+输出路径)
题意: FatMouse believes that the fatter a mouse is, the faster it runs. To disprove this, you want to ...
- [HDOJ1160]FatMouse's Speed(DP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1160 FatMouse believes that the fatter a mouse is, th ...
- 题解报告:hdu 1160 FatMouse's Speed(LIS+记录路径)
Problem Description FatMouse believes that the fatter a mouse is, the faster it runs. To disprove th ...
- 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 给你一些老鼠的体重和速度,问你最多需要几只可以证明体重越重速度越慢,并输出任意一组答案. 结构体 ...
- HDU - 1160 FatMouse's Speed 【DP】
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1160 题意 给出一系列的 wi si 要找出一个最长的子序列 满足 wi 是按照升序排列的 si 是按 ...
随机推荐
- css3过度和动画
一.过度(transition) transition:[transition-property] || [transition-duration] || [transition-timing-fun ...
- JAXB - Validate Document before It is Unmarshalled
Validation A considerable part of the XML Schema language deals with facets, enabling the programmer ...
- 第四章 jQuery中的事件
1.加载DOM jQuery中,在$(document).ready()方法内注册的事件,只要DOM就绪就会被执行,此时可能元素的关联文件未下载完. jQuery中的 load()方法,会在元素的on ...
- rs.open sql,conn,3,1中3,1代表什么
RecordSet中的open完全的语法是 SecordSet.Open Source,ActiveConnection,CursorType,LockType,Options 例如: rs.open ...
- 敌情篇 ——DDoS攻击原理
敌情篇 ——DDoS攻击原理 DDoS攻击基础 DDoS(Distributed Denial of Service,分布式拒绝服务)攻击的主要目的是让指定目标无法提供正常服务,甚至从互联网上消失,是 ...
- 【html】【19】高级篇--大事件时间轴
下载: http://sc.chinaz.com/jiaoben/131112181390.htm 其它: http://sc.chinaz.com/tag_jiaoben/shijianzhou.h ...
- 【html】【13】特效篇--下拉导航
html代码: <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" ...
- hdu 1316 How many Fibs?(高精度斐波那契数)
// 大数继续 Problem Description Recall the definition of the Fibonacci numbers: f1 := 1 f2 := 2 fn : ...
- 九度OJ 1024 畅通工程 -- 并查集、贪心算法(最小生成树)
题目地址:http://ac.jobdu.com/problem.php?pid=1024 题目描述: 省政府"畅通工程"的目标是使全省任何两个村庄间都可以实现公路交通(但 ...
- CenOS6.4 系统升级内核
获取要升级的内核版本的包 #wget -c https://www.kernel.org/pub/linux/kernel/v3.x/内核版本 若得到的内核的压缩格式为tar.xz,则需要两步解压 # ...