Fatmouse ' s speed
problem DescriptionFatmouse 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.
InputInput 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 S Econd 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 line s 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 2100 $4000110060008000 140060001900
Sample Output44597a set of data that is processed to the end of the filegive you some cow's weight, and speednow pick out as many cows as possible from these cows to make up a sequence that satisfies:weight from small to large strict decline, speed from large to small strictly increaseoutput can find out how many cows, but also output the number of cattlein fact, like the largest ascending sub-sequence, there are only 2 conditions, one increases, one decreases. And then record the number of the cows that were originally entered,This sort of order can still know his original serial number. output by the original ordinal
1#include <iostream>2#include <cstring>3#include <algorithm>4#include <cstdio>5 6 using namespacestd;7 8 Const intmaxn=1005;9 Ten intDP[MAXN];//The maximum value of the sequence of the ending element with the first I One intPRE[MAXN];//Record Sequence A - structNode - { the intW,s,num;//NUM Record order of inputs - }NODE[MAXN]; - - BOOLCMP (Node a,node B) + { - if(a.w==B.W) + returnA.s>B.S; A returna.w<B.W; at } - - //Output Path - voidOutputintcur) - { - if(pre[cur]!=-1) in output (pre[cur]); -cout<<node[cur].num<<Endl; to } + - intMain () the { * //freopen ("In.txt", "R", stdin); //Remember to comment out $ Panax Notoginseng intu,v; - inttot=1; the + while(cin>>u>>v) A { thenode[tot].w=u; +node[tot].s=v; -node[tot].num=tot++; $ } $ -Sort (node+1, node+tot,cmp); - thememset (pre,-1,sizeof(pre)); - Wuyi for(intI=1; i<tot;i++) thedp[i]=1; - Wu for(intI=1; i<tot;i++) - { About for(intj=1; j<i;j++) $ if(node[j].w<node[i].w&&node[j].s>node[i].s) - if(dp[j]+1>Dp[i]) - { -dp[i]=dp[j]+1; Apre[i]=J; + } the } - $ intans=0; the intcur; the for(intI=1; i<tot;i++) the if(dp[i]>ans) the { -ans=Dp[i]; inCur=i; the } the Aboutcout<<ans<<Endl; the the output (cur); the + return 0; -}
View Code
HDU 1160 Fatmouse ' s speed simple DP