Problem Descriptionfatmouse believes, the fatter a mouse is, the faster it runs. To disprove this, want to take the data in a collection of mice and put as large a subset of this data as possible int o A sequence So, the weights is increasing, but the speeds is decreasing.
Inputinput contains data for a bunch of mice, one mouse per line, terminated by end of file.
The data for a particular mouse would consist of a pair of integers:the first representing its size in grams and the Secon D representing its speed in centimeters per second. Both integers is between 1 and 10000. The data in all test case would contain information for at most of the mice.
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 is m[1], m[2],..., M[n] Then it must is 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 is correct, n should be as large as possible.
All inequalities is strict:weights must is strictly increasing, and speeds must be strictly decreasing. There may is many correct outputs for a given input, and your program only needs to find one.
Sample Input6008 13006000 2100500 20001000 40001100 30006000 20008000 14006000 12002000 1900
Sample Output44597
Main topic:
It's a big English question.
He gives you the mouse's weight and the speed of the run.
Then the longest descending sequence of speed when the weight is in ascending order
It doesn't matter, it's important to print the path.
Analysis:
is to sort the weight first.
Then find the longest descending sequence
The final output of the record path in the process of re-seeking
#include <stdio.h>#include<string.h>#include<math.h>#include<algorithm>#include<iostream>#include<math.h>#include<stdlib.h>using namespacestd;#defineINF 0XFFFFFFF#defineN 5000structnode{intNum,w,s;} A[n];intcmpConst void*x,Const void*y) { structNode *c,*D; C=(structNode *) x; D=(structNode *) y; if(c->w!=d->W)returnC->w-d->W; Else returnD->s-c->s;}intMain () {intI=0, Pre[n],dp[n]; while(SCANF ("%d%d", &A[I].W,&A[I].S)! =EOF) {Dp[i]=1; Pre[i]=0; A[i].num=i+1; I++; } intn=i,b,max=0; Qsort (A,n,sizeof(a[0]), CMP); for(i=0; i<n;i++) { for(intj=0; j<i;j++) { if(a[j].w<a[i].w&&a[j].s>a[i].s&&dp[j]+1>Dp[i]) {Dp[i]=dp[j]+1; Pre[i]=J; if(max<Dp[i]) {b=i; Max=Dp[i]; } } } } intAa[n]; printf ("%d\n", Max); aa[0]=A[b].num; I=1; while(1) { intj=Pre[b]; if(j==0) Break; Aa[i++]=A[j].num; b=J; } for(intj=i-1; j>=0; j--) printf ("%d\n", Aa[j]); return 0;}
Fatmouse ' s speed--hdu1160 (dp+ output path)