Description
Fatmouse believes that's 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.
Input
Input contains data for a bunch in 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.
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 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 Input
6008 13006000 2100500 20001000 40001100 30006000 20008000 14006000 12002000 1900
Sample Output
44597
Sort by decreasing the weight increment rate and finding the biggest string is mainly the path problem.
#include <cstdio>#include<cstdlib>#include<cmath>#include<iostream>#include<algorithm>#include<cstring>#include<vector>using namespacestd;#defineMAXN 10005#defineN 3000intDp[n],p[n],a[n];structnode{intw,s,t;} Q[n];intCMP (node E,node f) {if(E.W!=F.W)returne.w<F.W; returnE.s>F.s;}intMain () {intn=1; while(SCANF ("%d%d", &Q[N].W,&Q[N].S)! =EOF) {q[n].t=N; Dp[n]=1; P[n]=0; N++; } N=n-1; Sort (q+1, q+1+n,cmp); intmaxx=-12365478, M; for(intI=1; i<=n;i++) { for(intj=1; j<i;j++) { if(Q[i].w>q[j].w&&q[i].s<q[j].s&&dp[i]<=dp[j])///Dp[j]>=dp[i] that dp[i]=dp[j]+1 to be saved makes sense.{Dp[i]=dp[j]+1; P[i]=j;///P[i]=j Keep the previous location easy to find in turn if(dp[i]>=Maxx) {Maxx=Dp[i]; M=i;///where to keep the maximum value } } } } intX=m,i=0; while(x) {a[i++]=x;///Extract to ArrayX=P[X];///Search in turn} printf ("%d\n", i); while(i>0) {i--; printf ("%d\n", q[a[i]].t);///Output } return 0;}
HDU path problems in 1160 DP