(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> ...
随机推荐
- HDOJ-ACM1012(JAVA)
这道题很简单,主要是弄懂题意和注意输出: 输出的完整结果如下: n e - ----------- 0 1 1 2 2 2.5 3 2.666666667 4 2.708333333 5 2.7166 ...
- ZOJ-3721 Final Exam Arrangement 贪心
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3721 容易的贪心题,排个序.. //STATUS:C++_AC_ ...
- FPGA开发板
kingst.cnblogs.com 各种应用需要的接口不同: 做数字信号处理的,需要有AD/DA, 做图像处理,需要有图像接口.如果是通信的,需要有通信的接口,例如PCI/LVDS等.... 然后根 ...
- post方法
CookieContainer cookie = new CookieContainer(); private string HttpPost(string Url, string postDataS ...
- mongoDB中的连接池(转载)
一.mongoDB中的连接池 刚上手MongoDB,在做应用时,受以前使用关系型数据库的影响,会考虑数据库连接池的问题! 关系型数据库中,我们做连接池无非就是事先建立好N个连接(connection) ...
- 2016-11-15NOIP模拟赛
AM学军OJ T1 暴力 #include<bits/stdc++.h> using namespace std; typedef long long LL; + ; int len, p ...
- 理解SQL Server中索引的概念
T-SQL查询进阶--理解SQL Server中索引的概念,原理以及其他 简介 在SQL Server中,索引是一种增强式的存在,这意味着,即使没有索引,SQL Server仍然可以实现应有的功能 ...
- Redis: OOM command not allowed when used memory > ‘maxmemory
Redis: OOM command not allowed when used memory > ‘maxmemory’ 解决方式: $ vim /etc/redis/6903.conf ma ...
- 传值(VIP)
页面间传值主要分为:1.属性传值.2.协议传值.3.单例传值.4.Block传值: 界面之间的传值: 1.从前往后:属性传值 2.从后往前:代理传值 3.多界面之间的传值 — 单例传值 ...
- iOS从生成证书到打包上架-02(详细2016-10最新)
由于篇幅的限制,这篇接着上一篇(关于证书)写的,有需要的小伙伴可以先阅读上一篇 2.在App Store创建应用 1.回到Account,点击iTunes Connect 2.点击我的App 3.点击 ...