FatMouse believes that the fatter a mouse is, the faster it runs. To disprove this, you want to take the data on a collection of mice and put as large a subset of this data as possible into a sequence so that the weights are increasing, but the speeds are decreasing. 

InputInput contains data for a bunch of mice, one mouse per line, terminated by end of file.

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. 
OutputYour program should output a sequence of lines of data; the first line should contain a number n; the remaining n lines should each contain a single positive integer (each one representing a mouse). If these n integers are m[1], m[2],..., m[n] then it must be the case that

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. 
Sample Input

6008 1300
6000 2100
500 2000
1000 4000
1100 3000
6000 2000
8000 1400
6000 1200
2000 1900

Sample Output

4
4
5
9
7
#include <bits/stdc++.h>
#define ms(a) memset(a,-1,sizeof(a))
using namespace std; const int M = 1009; int dp[M];
int pre[M]; struct node{
int w,v,id;
bool operator <(const node &n)const{
if(w>=n.w)return true;
else if (w==n.w) return v<n.v;
else return false;
}
};
node a[M]; bool cmp(node a, node b){
return a.w < b.w;
} int main()
{
int i = 0,n = 0;
ms(pre);
while(scanf("%d%d",&a[i].w,&a[i].v) != EOF)
{
a[i].id = i+1;
i++;
n++;
}
sort(a,a+n);
for(int i=0;i<n;i++)dp[i]=1;
for(int i = 0; i < n; i ++)
for(int j = 0; j < i; j++)
{
if(a[i].w < a[j].w && a[i].v > a[j].v)
{
if(dp[i] < dp[j] + 1)
dp[i] = dp[j] + 1,pre[i] = j;
}
} int ans=-1,pos = 0;
for(int i=0;i<n;i++){
if(ans<dp[i]){
ans=dp[i];
pos=i;
}
}
printf("%d\n",dp[pos]);
while(pos!=-1){
printf("%d\n",a[pos].id);
pos=pre[pos];
}
return 0;
}

HDU 1160的更多相关文章

  1. HDU 1160 DP最长子序列

    G - FatMouse's Speed Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64 ...

  2. HDU 1160 FatMouse's Speed(要记录路径的二维LIS)

    FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  3. 怒刷DP之 HDU 1160

    FatMouse's Speed Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Su ...

  4. HDU 1160 FatMouse's Speed (DP)

    FatMouse's Speed Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Su ...

  5. HDU - 1160 FatMouse's Speed 动态规划LIS,路径还原与nlogn优化

    HDU - 1160 给一些老鼠的体重和速度 要求对老鼠进行重排列,并找出一个最长的子序列,体重严格递增,速度严格递减 并输出一种方案 原题等于定义一个偏序关系 $(a,b)<(c.d)$ 当且 ...

  6. hdu 1160 FatMouse's Speed 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1160 题目意思:给出一堆老鼠,假设有 n 只(输入n条信息后Ctrl+Z).每只老鼠有对应的weigh ...

  7. HDU 1160 FatMouse's Speed (sort + dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1160 给你一些老鼠的体重和速度,问你最多需要几只可以证明体重越重速度越慢,并输出任意一组答案. 结构体 ...

  8. FatMouse's Speed (hdu 1160)

          #include <iostream> #include <cstdio> #include <cstring> #include <algori ...

  9. (最长上升子序列 并记录过程)FatMouse's Speed -- hdu -- 1160

    http://acm.hdu.edu.cn/showproblem.php?pid=1160 FatMouse's Speed Time Limit: 2000/1000 MS (Java/Other ...

  10. HDU 1160(两个值的LIS,需dfs输出路径)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1160 FatMouse's Speed Time Limit: 2000/1000 MS (Java/ ...

随机推荐

  1. linux系统下键盘按键的重新映射——xmodmap工具和xev工具

    大家会不会有时候,感觉键盘上的某几个键用起来不是很方便,打字打久了很容易手指头疼呢? 例如大家使用vim编辑器时, 经常需要使用到esc键,而该键在左上角,很不方便的.再比如写程序的时候,经常会使用到 ...

  2. 第四百一十二节,python接口,抽象方法抽象类

    Python接口 在Python中所谓的接口,有两种,一种是通过url访问的api接口 一种是一个对象的接口 构造接口 class Ijiekou: """ 定义一个约束 ...

  3. js多个(N)个数组的的元素组合排序算法,多维数组的排列组合或多个数组之间的排列组合

    现在有一批手机,其中颜色有['白色','黑色','金色','粉红色']:内存大小有['16G','32G','64G','128G'],版本有['移动','联通','电信'],要求写一个算法,实现[[ ...

  4. ES6 扩展运算符 三点(...)

    含义 扩展运算符( spread )是三个点(...).它好比 rest 参数的逆运算,将一个数组转为用逗号分隔的参数序列. console.log(...[, , ]) // 1 2 3 conso ...

  5. 3D Object Classification With Point Convolution —— 点云卷积网络

    今天刚刚得到消息,之前投给IROS 2017的文章收录了.很久很久没有写过博客,今天正好借这个机会来谈谈点云卷积网络的一些细节. 1.点云与三维表达 三维数据后者说空间数据有很多种表达方式,比如:RG ...

  6. 机器人学 —— 机器人感知(Mapping)

    对于移动机器人来说,最吸引人的莫过于SLAM,堪称Moving Robot 皇冠上的明珠.Perception 服务于 SLAM,Motion Plan基于SLAM.SLAM在移动机器人整个问题框架中 ...

  7. Xcode - 因为证书问题经常报的那些错

    1.确认下证书是不是开发证书,如果是发布证书就会出现这样的提示. 2.证书失效了,去开发者中心重新生成一个. 3.包标识符不与描述文件包含的包标识符不一致,按照它的提示换一下就好了,最好不要点 Fix ...

  8. Nodejs exec和spawn的区别

    spawn child_process.spaen会返回一个带有stdout和stderr流的对象.你可以通过stdout流来读取子进程返回给Node.js的数据. stdout拥有’data’,’e ...

  9. 阅历>感悟

    1.强扭的瓜不甜.在招聘的时候,面试官看不上你,你也不用赖着要去,你去能干好工作吗?面试官通常比你更清楚这个是事情.在比如谈恋爱,姑娘有更好的目标,不喜欢你了,决定离开你了,你再怎么挽留都是没意义的, ...

  10. Java课程课堂测试05

    大致要求:将十道计算题输出至TXT文件,再读取文件至控制台,然后在控制台中输入答案并评判对错 我在大致的要求当中已经将我的设计思路体现了出来 首先,实现计算题的设计,第二步要对计算题循环,将答案存到一 ...