HDU1160 FatMouse's Speed(DP,最长下降子序列)
来源:互联网 发布:雅格迪斯号 淘宝 编辑:程序博客网 时间:2024/05/16 13:45
题目链接
FatMouse's Speed
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 7883 Accepted Submission(s): 3499
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
#include<stdio.h>#include<iostream>#include<stdlib.h>#include<algorithm>#include<time.h>#include<ctype.h>#include<string.h>#include<math.h>#include<string>#define sqr(x) (x)*(x)#define INF 0x1f1f1f1f#define PI 3.1415926535#define mm using namespace std;struct rat{int w,s,index;}r[1001];int dp[1001],pre[1001],temp[1001];int cmp(const void *x, const void *y){struct rat *a=(struct rat *)x;struct rat *b=(struct rat *)y;return a->w - b->w;}int main(){int cnt=0;while(~scanf("%d%d",&r[cnt].w,&r[cnt].s)){r[cnt++].index=cnt+1;}qsort(r,cnt,sizeof(struct rat),cmp);memset(dp,0,sizeof(dp));memset(pre,-1,sizeof(pre));memset(temp,0,sizeof(temp));dp[0]=1;int ans,k,end=0;for (int i=1;i<cnt;i++){ans=dp[i];for (int j=0;j<i;j++){if (r[i].s<r[j].s && dp[j]>=ans){ans=dp[j];pre[i]=j;}}dp[i]=ans+1;}ans=0;for (int i=0;i<cnt;i++){if (dp[i]>ans){ans=dp[i];end=i;}}k=end;temp[k]=1;while(k>=0){k=pre[k];temp[k]=1;}cout<<ans<<endl;for (int i=0;i<cnt;i++){if (temp[i])cout<<r[i].index<<endl;}return 0;}
1 0
- HDU1160 FatMouse's Speed(DP,最长下降子序列)
- hdu1160 FatMouse's Speed 最长下降子序列 及其打印
- HDU1160 - FatMouse's Speed(最长下降子序列+打印路径)
- hdu1160 FatMouse's Speed 最长下降子序列 动态规划
- hdu1160 FatMouse's Speed 【最长下降子序列+输出】
- hdu1160 - FatMouse's Speed (dp 最长有序子序列问题)
- HDU1160 FatMouse's Speed(DP,最长递增子序列)
- hdu1160 FatMouse's Speed (求最长严格下降子序列路径)
- hdoj1160 FatMouse's Speed ( STL + 最长下降子序列 /DP)
- FatMouse's Speed hdu1160 最长有序子序列
- hdu1160 FatMouse's Speed 最长上升子序列 LIS
- hdu 1160 FatMouse's Speed( 最长下降子序列 )
- hdu1160 FatMouse's Speed 最长上升子序列以及记录路径 DP
- hdu1160 FatMouse's Speed (子序列
- HDU 1160 FatMouse's Speed (dp, 最长子序列)
- HDU1160 FatMouse's Speed 带路径的最长上升子序列问题
- hdu1160简单dp最长下降子序列
- HDOJ1160 FatMouse's Speed[dp](最长上升子序列)
- app后端设计(8)-- 数据库分表
- 阿里云快速挂载硬盘教程
- PPT
- MTK Android Driver :add a new key
- HttpURLConnection请求数据流的写入(write)和读取(read)
- HDU1160 FatMouse's Speed(DP,最长下降子序列)
- AD6交互式布线,智能布线快捷键的介绍
- struts2 不能上传图片
- 九度OJ 1372 最大子向量和(连续子数组的最大和)
- C# [STAThread]
- Eclipse JAD反编译插件安装方法
- Android优秀开源项目
- 失落的C语言结构体封装艺术
- J2EE笔试面试题