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 是按 ...
随机推荐
- sql server 表变量、表类型、临时表
sql server 中临时表分为会话临时表和永久临时表.会话临时表在会话结束后自动被删除,永久临时表与基本表的使用上基本无差异,需要显示调用drop将其删除. 创建临时表 创建会话临时表 creat ...
- 2014年下半年计划—写博客,旅游,带女朋友拍写真
前言:写这篇博客之前,一直在网上,看各位大牛写的博文,发布的视频等.当然由于自己的初来乍到,人生地不"熟"儿的,也吃了不少亏,走了不少弯路.本着一颗学习的心,携着向各 ...
- JAXB - Annotations, The Object Factory: XmlRegistry, XmlElementDecl
To be able to create objects from XML elements, the unmarshaller must have an object factory with me ...
- 【C#4.0图解教程】笔记(第19章~第25章)
第19章 泛型 1.泛型概念 泛型提供了一种更准确地使用有一种以上的类型的代码的方式. 泛型允许我们声明类型参数化的代码,我们可以用不同的类型进行实例化. 泛型不是类型,而是类型的模板. 2.声明 ...
- ###再探Makefile
使用makefile.以前刚开始接触Makefile的时候,写过一个最简单的Makefile.点击查看Evernote原文. #@author: gr #@date: 2014-07-20 #@ema ...
- Core Animation之CABasicAnimation
在iOS中,图形可分为以下几个层次: 越上层,封装程度越高,动画实现越简洁越简单,但是自由度越低:反之亦然.本文着重介绍Core Animation层的基本动画实现方案. 在iOS中,展示动画可以类比 ...
- 线程间通信--生产者消费者 升级版JDK5
import java.util.concurrent.locks.*; /*1.新的解锁,上锁操作,据说是jdk5.0升级版,以前的枷锁,解锁都是隐藏的,默认的,现在变成显式 2.新的异常处理方式 ...
- C bit 操作
C 位 操作 一.C bit 操作(C语言 二进制位 操作) 1.Setting a bit Use the bitwise OR operator (|) to set a bit. number ...
- InstallShield Custom Dialog
InstallShield 2008 Screen Layout is designed as below. Use toolbox to edit screen layout. 1> Set ...
- OpenJudge/Poj 1979 Red and Black / OpenJudge 2816 红与黑
1.链接地址: http://bailian.openjudge.cn/practice/1979 http://poj.org/problem?id=1979 2.题目: 总时间限制: 1000ms ...