HDU Fatmouse ' s speed (LIS)

Source: Internet
Author: User

Fatmouse ' s speed

Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 9871 Accepted Submission (s): 4374
Special Judge


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

Sourcezhejiang University Training Contest 2001

Recommendignatius This problem, a bit of egg pain first is the input, the input of the problem is not quite the same = = can be seen to this question on the LIS, but unlike the general Lis is this problem to path printing so that the DP equation or lis DP equation: dp[i]=dp[j]+ 1 (a[j].s>a[i].s && a[i].w!=a[j].w) or do you want to learn the path of the different types of problems print = = Here The pre[] array is used to record the subscript of the previous state transferred to the current state and then recursively find the initial state, That is, the pre[i]=-1, and then the output in turn.
#include <iostream>#include<cstdio>#include<cstring>#include<cmath>#include<stdlib.h>#include<queue>#include<stack>#include<algorithm>#defineLL __int64using namespacestd;Const intmaxn=10000+ -;Const intinf=0x3f3f3f3f;Const Doubleeps=1e-9;intdir4[][2]={{0,1},{1,0},{0,-1},{-1,0}};intdir8[][2]={{0,1},{1,1},{1,0},{1,-1},{0,-1},{-1,-1},{-1,0},{-1,1}};intdir_8[][2]={{-2,1},{-1,2},{1,2},{2,1},{2,-1},{1,-2},{-1,-2},{-2,-1}};structnode{intW; ints; intindex; BOOL operator< (ConstNode A)Const    {        if(W!=A.W)returnw<A.W; returnS>A.S; }}A[MAXN];intDP[MAXN],PRE[MAXN];voidPrintintp) {    if(pre[p]!=-1) print (pre[p]); printf ("%d\n", A[p].index);}intMain () {intWeight,speed,cnt=0;  while(SCANF ("%d%d", &weight,&speed)! =EOF) {A[CNT].W=weight; A[cnt].s=Speed ; A[cnt].index=cnt+1; CNT++; } sort (A,a+CNT); Memset (DP,0,sizeof(DP)); memset (PRE,-1,sizeof(pre)); dp[0]=1; intid,maxn=-INF;  for(intI=1; i<cnt;i++) {Dp[i]=1;  for(intj=0; j<i;j++)        {            if(A[I].W!=A[J].W && a[i].s<a[j].s) {                if(dp[j]+1>Dp[i]) {Dp[i]=dp[j]+1; Pre[i]=K; }            }        }        if(dp[i]>MAXN) {MAXN=Dp[i]; ID=i; }} printf ("%d\n", Dp[id]);    print (ID); return 0;}
View Code

HDU Fatmouse ' s speed (LIS)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.