FatMouse's Speed

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 7213    Accepted Submission(s): 3181
Special Judge

Problem Description
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.
 
Input
Input 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.

 
Output
Your
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
                       //EOF结束用ctrl+z
Sample Output
4
4
5
9
7
分析:实际上是让求 单调递增序列的,双向的
AC代码:
 #include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
struct node //老鼠的属性
{
int w; //体重
int s; //速度
int x; //输入时的顺序号
}mice[];
int cmp(node a,node b) //以体重为标准,将老鼠按体重递减排序
{
return a.w<b.w;
}
int main()
{
int n=;
int i,j;
int much[],head[]; //分别记录第i只老鼠为止,子序列长度与前驱存储位置(mice数组中下标)
while(scanf("%d %d",&mice[n].w,&mice[n].s)!=EOF)
mice[n].x=n+,n++;
sort(mice,mice+n+,cmp); //排序
head[]=-; //终止标记
much[]=;
int max1=,x; //由第一只老鼠到当前检索位置为止,子序列的最大长度和其前驱位置在前驱记录数组head中的下标
for(i=;i<=n;i++)
{
head[i]=-;
much[i]=;
for(j=;j<i;j++)
{
if(mice[i].w>mice[j].w && mice[i].s<mice[j].s && much[j]+>much[i]) //体重严格递增,速度严格递减,子序列更长
{
much[i]=much[j]+;
head[i]=j;
if(much[i]>max1) //前驱处理
{
max1=much[i];
x=i; }
//cout<<"i="<<i<<"j="<<j<<endl;
} }
}
//cout<<"X==="<<x<<endl;
int road[];
i=;
while() //处理路劲记录
{
//cout<<"X="<<mice [x].x<<endl;
road[i++]=mice[x].x;
//cout<<x<<" "<<head[x]<<endl;
x=head[x];
if(x==-)
break;
}
printf("%d\n",max1);
for(i--;i>=;i--)
printf("%d\n",road[i]);
return ;
}
 

hdoj1160 FatMouse's Speed 动态规划的更多相关文章

  1. hdu FatMouse's Speed 动态规划DP

    动态规划的解决方法是找到动态转移方程. 题目地址:http://acm.hdu.edu.cn/game/entry/problem/show.php?chapterid=3&sectionid ...

  2. [HDOJ1160]FatMouse's Speed(DP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1160 FatMouse believes that the fatter a mouse is, th ...

  3. HDU 1160 FatMouse's Speed 动态规划 记录路径的最长上升子序列变形

    题目大意:输入数据直到文件结束,每行两个数据 体重M 和 速度V,将其排列得到一个序列,要求为:体重越大 速度越低(相等则不符合条件).求这种序列最长的长度,并输出路径.答案不唯一,输出任意一种就好了 ...

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

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

  5. HDU 1160 FatMouse's Speed (动态规划、最长下降子序列)

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

  6. FatMouse's Speed——J

    J. FatMouse's Speed FatMouse believes that the fatter a mouse is, the faster it runs. To disprove th ...

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

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

  8. HDU 1160 FatMouse's Speed (DP)

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

  9. FatMouse's Speed(HDU LIS)

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

随机推荐

  1. 使用QQ截图右键菜单

    (1)登录QQ: (2)同时按住Shift+Ctrl+Alt+A四个键,然后点击右键: (3)松开Shift键(只松开Shift键,其他键不要松开).惊喜出现了吧!

  2. iphone openssh

    安装openssh 用户名:默认是 root 密码:默认是 alpine 修改登陆密码:passwd

  3. [Done][DUBBO] dubbo Thread pool is EXHAUSTED!

    异常信息: com.alibaba.dubbo.remoting.ExecutionException: class com.alibaba.dubbo.remoting.transport.disp ...

  4. Python之str方法

    # -*- coding: utf-8 -*- #python 27 #xiaodeng #Python之str方法 #http://python.jobbole.com/82655/ #str为一个 ...

  5. VC线程同步方法

    VC MFC中线程同步对象的区别 临界区 CCriticalSection,在用户模式工作,适用于保护线程间共享资源,一个线程可以多次Lock不会出错.不支持在多进程之间工作.互斥量 CM ...

  6. 【laravel5.4+vue.js】laravel 循环三维数组,解决:htmlentities() expects parameter 1 to be string, array given

    laravel循环三维数组   +++   vue.js循环三维数组  (数据均是以三维数组形式存在的) <form-item label="权限名称" prop=" ...

  7. js 取值 getElementsByTagName,getElementsByName

    getElementsByTagName,getElementsByName  获取的值是数组的所以用[0][1]引用 1 <select multiple size="2" ...

  8. nyoj-----前缀式计算

    前缀式计算 时间限制:1000 ms  |           内存限制:65535 KB 难度:3   描述 先说明一下什么是中缀式: 如2+(3+4)*5这种我们最常见的式子就是中缀式. 而把中缀 ...

  9. [Python]网络爬虫(七):Python中的正则表达式教程(转)

    接下来准备用糗百做一个爬虫的小例子. 但是在这之前,先详细的整理一下Python中的正则表达式的相关内容. 正则表达式在Python爬虫中的作用就像是老师点名时用的花名册一样,是必不可少的神兵利器. ...

  10. Windows Server 2008的远程控制修改端口,谨防非法远程连接

    1.首先在Windows Server 2008服务器系统桌面上依次单击“开始”/“运行”命令,在弹出的系统运行对话框中,输入字符串命令“regedit”,单击回车键后,打开对应系统的注册表编辑界面; ...