HDU1160 FatMouse's Speed(DP,最长递增子序列)
来源:互联网 发布:淘宝突然登不上去了 编辑:程序博客网 时间:2024/05/29 14:30
题目:
FatMouse's Speed
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 15266 Accepted Submission(s): 6731
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.
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.
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 13006000 2100500 20001000 40001100 30006000 20008000 14006000 12002000 1900
Sample Output
44597
Source
Zhejiang University Training Contest 2001
Recommend
Ignatius
#include <stdio.h>#include <string.h>#include <iostream>#include <stack>#include <queue>#include <vector>#include <algorithm>#define mem(a,b) memset(a,b,sizeof(a))using namespace std;struct node{ int x,y,pre;} a[10010];int dp[10010];bool cmp(node a,node b){ if(a.x!=b.x) return a.x<b.x; return a.y>b.y;}struct md{ int st,front;} b[10010];int flag=0;void shuchu(int i){ if(b[i].front) shuchu(b[i].front);//递归输出 else { flag=1; printf("%d\n",b[i].st); return; } if(flag) { printf("%d\n",b[i].st); return; }}int main(){ int weight,speed,num=1; while(~scanf("%d%d",&weight,&speed))//输入数据 { a[num].x=weight; a[num].y=speed; a[num].pre=num; num++;//以num作为下标,记录体重和速度的值 } sort(a,a+num,cmp);//因为输出只要下标,所以这里可以打乱顺序,按体重从小到大排列 for(int i=0; i<num; i++) { dp[i]=1;//初始化为1,因为最少都有一个 b[i].st=a[i].pre;//用b来记录下标 } for(int i=2; i<num; i++) { for(int j=i-1; j>=0; j--) if(a[i].y<a[j].y&&a[i].x>a[j].x&&dp[i]<dp[j]+1)//求递增子序列,比较一下体重和素的的大小 { dp[i]=dp[j]+1;//增加序列长度 b[i].st=a[i].pre;//记录下标 b[i].front=j; } } int maxx=0,k; for(int i=0; i<num; i++) if(maxx<dp[i]) { maxx=dp[i];//找出最长的 k=i; } printf("%d\n",maxx); shuchu(b[k].front);//打印路径 printf("%d\n",b[k].st);//输出最后一个 return 0;}
0 0
- HDU1160 FatMouse's Speed(DP,最长递增子序列)
- HDU1160 FatMouse's Speed(DP,最长下降子序列)
- hdu1160 - FatMouse's Speed (dp 最长有序子序列问题)
- FatMouse's Speed hdu1160 最长有序子序列
- hdu1160 FatMouse's Speed 最长下降子序列 及其打印
- HDU1160 - FatMouse's Speed(最长下降子序列+打印路径)
- hdu1160 FatMouse's Speed 最长下降子序列 动态规划
- hdu1160 FatMouse's Speed 【最长下降子序列+输出】
- hdu1160 FatMouse's Speed 最长上升子序列 LIS
- hdu1160 FatMouse's Speed 最长上升子序列以及记录路径 DP
- hdu1160 FatMouse's Speed (子序列
- (HDU 1160) FatMouse's Speed dp (最长递增子序列 , 两个因素决定)
- hdu1160 FatMouse's Speed (求最长严格下降子序列路径)
- HDU1160 FatMouse's Speed 带路径的最长上升子序列问题
- hdoj1160 FatMouse's Speed ( STL + 最长下降子序列 /DP)
- HDOJ1160 FatMouse's Speed[dp](最长上升子序列)
- HDU 1160 FatMouse's Speed (dp, 最长子序列)
- HDU 1160 FatMouse's Speed--dP--(元素1递增元素2递降的最长子序列)
- 文本分类
- [FAQ19142]VOIP APK与普通电话交互导致普通电话无声
- 保存JSP页面状态的4个内置对象
- 浅谈 SQL 中的锁(四)如何检查重复用户
- javaWeb中前台页面怎么获取根路径并以何种方式打开链接
- HDU1160 FatMouse's Speed(DP,最长递增子序列)
- 关于php的unset失败的问题
- dsp调试常见问题
- 2-3-4树的java实现
- UI学习
- UpdatePanel控件的使用
- 一样
- 排序算法---简单的选择排序
- log4net 使用及config文件配置