(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> ...
随机推荐
- redis在.NET下的使用
windows SEVER包:http://code.google.com/p/servicestack/wiki/RedisWindowsDownload windows仅用来测试,性能不如在lin ...
- 注册表-在IE上永久显示我的名字"www.baidu.com - 朱建强"
HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\新建字符串 名为:window title值为:"朱建强"
- 在Linux系统中修改IP地址
在Linux系统中,通过编辑网络配置文件,设置系统IP地址,当然要在root权限下执行,具体步骤如下: 1.切换路径到/etc/sysconfig/network-scripts [root@Comp ...
- jquery实现公告上下滚动显示
js: // JavaScript Documentfunction b(){ t = parseInt(x.css('top')); y.css('top','19px'); x.animate({ ...
- JS继承的几种方式
JS作为面向对象的弱类型语言,继承也是其非常强大的特性之一. 既然要实现继承,那么我们先定义一个父类: // 定义一个动物类 function Animal (name) { // 属性 this.n ...
- iOS不勾选设置,实现某个界面强制横屏
1.在不勾选横屏的前提下,实现某一个界面横屏显示,比如播放视频.图表显示等. 2.只能Present跳转,Push会无效. 3.实现代码 在需要横屏的VC里,添加如下代码 #pragma mark 强 ...
- linux命令行模式下实现代理上网
有些公司的局域网环境,例如我们公司的只允许使用代理上网,图形界面的很好解决就设置一下浏览器的代理就好了,但是linux纯命令行的界面就....下面简单几步就可以实现了! 一.命令行界面的一般代理设置方 ...
- 结构体数组(C++)
1.定义结构体数组 和定义结构体变量类似,定义结构体数组时只需声明其为数组即可.如: struct Student{ int num; char name[20]; char sex[5]; int ...
- ThinkPad E431怎样关闭触摸板
ThinkPad E431怎样关闭触摸板 系统环境:win 7 旗舰版 1.下载驱动程序 到官方下载UltraNav驱动.參考例如以下图所看到的: Think Pad系列关闭触摸板须要安装专门的驱动程 ...
- Eclipse的LogCat总是自动清空怎么办?
我们经常会遇到这样一种情况,由于Log太多,导致我们的LogCat总是被自动清空,该怎么办?错误信息看不到,How to do? 其实,我们通过adb shell来解决这个问题. 1.配置环境变量 环 ...