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 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
Test Instructions: given n mice, the longest sequence is required, and the sequence requires that the weight of each mouse be strictly increased, while the speed is strictly decreasing.
Ideas: It is easy to think of a sort of attribute first, then DP, because the output is the maximum length and the position of the original sequence of each element, so record the position in the original array, each DP transfer, Dp[i] <=Dp[j] + 1 it is necessary to record the position of the element into the container and the final output.
1#include <stdio.h>2#include <iostream>3#include <string.h>4#include <algorithm>5 #define MAXX10000106 using namespacestd;7 8 structSion9 {Ten intW, S, K; One}a[1010]; A - - intCMP (sion A, sion B) the { - returnA.S >B.S; - } - + - + intdp[1010], re[10010], b[1010]; A intMain () at { - intn =0; - intMa =0, Mai =0; -re[0] =0; - while(Cin >> A[N].W >>a[n].s) -Re[n] =0, inA[N].K = n +1, -dp[n++] =1; to +Sort (A, A +N, CMP); - for(inti =0; I < n; i++) the { * for(intj =0; J < I; J + +) $ {Panax Notoginseng if(A[i].w > A[J].W && dp[i] <= Dp[j] +1)//Note <= - { theDp[i] = Dp[j] +1; + ARE[A[I].K] =A[J].K; the if(Ma <Dp[i]) +Ma = dp[i], Mai =A[I].K; - } $ $ } - } -n =0; theprintf"%d\n", MA); - while(Re[mai])Wuyi { theb[n++] =mai; -Mai =Re[mai]; Wu } -b[n++] =mai; About for(inti = n1; I >=0; i--) $printf"%d\n", B[i]); -}
HDU 1160 fatmouse ' s speed SORT+DP