(hdu)1160 FatMouse's Speed
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.
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.
6000 2100
500 2000
1000 4000
1100 3000
6000 2000
8000 1400
6000 1200
2000 1900
4
5
9
7
题意 找一组最长的数据,数据的体重逐渐增加,速度逐渐减小,输出序列标号
方法 在体重递增的序列中,找速度最长递减序列,同时记住每个序列的上个序列
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <math.h>
#include <vector>
using namespace std;
#define N 4000
#define ll long long
#define INF 0x3f3f3f3f
#define met(a,b) memset(a,b,sizeof(a));
vector<vector<int> >Q;
struct node
{
int p,w,i,l; } s[N];
int dp[N];
int cmp(node a,node b)
{
if(a.w!=b.w)
return a.w>b.w;
return a.p<b.p;
}
int main()
{
int k=;
while(scanf("%d%d",&s[k].w, &s[k].p)!=EOF)
{
s[k].i=k+;
s[k].l=-;
k++;
}
sort(s,s+k,cmp);
for(int i=; i<=k; i++)
dp[i]=;
dp[]=;
int ans=;
for(int i=; i<k; i++)
{
for(int j=; j<i; j++)
{
if(s[i].p>s[j].p && s[i].w<s[j].w)
{
if(dp[j]+>=dp[i])
{
dp[i]=dp[j]+;
s[i].l=j;
}
} if(dp[i]>dp[ans])
ans=i;
}
}
printf("%d\n",dp[ans]);
while(s[ans].l!=-)
{
printf("%d\n",s[ans].i);
ans=s[ans].l;
}
printf("%d\n",s[ans].i);
return;
}
(hdu)1160 FatMouse's Speed的更多相关文章
- 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 (DP)
FatMouse's Speed Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Su ...
- (hdu)5391 Zball in Tina Town
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5391 Problem Description Tina Town is a friendl ...
- (hdu)1285 确定比赛名次
Problem Description 有N个比赛队(<=N<=),编号依次为1,,,....,N进行比赛,比赛结束后,裁判委员会要将所有参赛队伍从前往后依次排名,但现在裁判委员会不能直接 ...
- 题解报告: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(最长不下降子序列+输出路径)
题意: FatMouse believes that the fatter a mouse is, the faster it runs. To disprove this, you want to ...
- HDU 1160 FatMouse's Speed(DP)
点我看题目 题意 :给你好多只老鼠的体重和速度,第 i 行代表着第 i 个位置上的老鼠,让你找出体重越大速度越慢的老鼠,先输出个数,再输出位置. 思路 :看题的时候竟然脑子抽风了,看了好久愣是没明白题 ...
- 【最长上升子序列记录路径(n^2)】HDU 1160 FatMouse's Speed
https://vjudge.net/contest/68966#problem/J [Accepted] #include<iostream> #include<cstdio> ...
随机推荐
- 判断html中的滚动条
在工作中需要调整jqgrid的列宽,但是不希望有横向滚动条,因为是固定的列宽,当显示区域缩小后,数据会出现竖型滚动条 这个时候需要判断竖型滚动条是否存在进行列宽的调整. 自己调查了一下,发现滚动条可以 ...
- hdu5564--Clarke and digits(数位dp+矩阵快速幂)
Clarke and digits 问题描述 克拉克是一名人格分裂患者.某一天,克拉克变成了一个研究人员,在研究数字. 他想知道在所有长度在[l,r]之间的能被7整除且相邻数位之和不为k的正整数有多少 ...
- 北京Uber优步司机奖励政策(2月3日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...
- 版本控制Subversion TortoiseSVN apache VisualSVN笔记(转载)
转载于http://blog.sina.com.cn/s/blog_6b94d5680101m7ah.html Subversion(简称svn)是近年来崛起的版本管理软件,是cvs的接班人.目前,绝 ...
- 如何通过进程名获取进程ID
博客搬到了fresky.github.io - Dawei XU,请各位看官挪步.最新的一篇是:如何通过进程名获取进程ID.
- WINFORM 自定义开关按钮控件-
本文章转载:http://www.cnblogs.com/feiyangqingyun/archive/2013/06/15/3137597.html OK,大工告成,上图演示效果. 源码下载:htt ...
- linux下lighttpdserver的具体安装步骤 以及对flv流媒体的支持配置
准备条件: a,创建/usr/local/lighttpd文件夹,用于安装lighttpd b,创建lighttpd用户password为lighttpd账号,用于lighttpd的启动用户 c,安装 ...
- [Webpack 2] Use Karma for Unit Testing with Webpack
When writing tests run by Karma for an application that’s bundled with webpack, it’s easiest to inte ...
- PHP获取客户端和服务器IP地址
/** * 获取客户端IP地址 * @return string */ function get_client_ip() { if(getenv('HTTP_CLIENT_IP')){ $client ...
- schedule() 和 scheduleAtFixedRate() 的区别--转载
1. schedule() ,2个参数方法:在执行任务时,如果指定的计划执行时间scheduledExecutionTime <= systemCurrentTime,则task会被立即执行. ...