uva10131 is bigger Smarter? (classic dp, longest ascending subsequence, note save path section)

Source: Internet
Author: User

Is bigger Smarter?
The problem

Some people think, the bigger an elephant are, the smarter it is. To disprove this, you want the data in a collection of elephants and put as large a subset of this data as Possibl e into a sequence so, the weights is increasing, but the IQ's is decreasing.

The input would consist of data for a bunch of elephants, one elephant per line, terminated by the end-of-file. The data for a particular elephant would consist of a pair of integers:the first representing its size in kilograms and th e second representing its IQ in hundredths of IQ points. Both integers is between 1 and 10000. The data would contain information for in most of the elephants. Elephants may have the same weight, the same IQ, or even the same weight and IQ.

Say the numbers on the i-th data line is w[i] and s[i]. 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 of the representing an elephant). If these n integers is a[1], a[2],..., A[n] Then it must is the case that

W[a[1]] < w[a[2] [< ... < W[a[n]]

and

S[A[1]] > s[a[2] [> ... > S[a[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 IQs 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 1300
6000 2100
500 2000
1000 4000
1100 3000
6000 2000
8000 1400
6000 1200
2000 1900

Sample Output

4
4
5
9
7

/*AUTHOR:ZCC; Solve: In descending order of the second keyword, it is converted to the lis*/to find the first key word#include <iostream>#include <algorithm>#include <map>#include <cstdio>#include <cstdlib>#include <vector>#include <cmath>#include <cstring>#include <stack>#include <string>#include <fstream>#define PB (s) push_back (s)#define CL (A, B) memset (A,b,sizeof (a) )#define BUG printf ("===\n");using namespace STD;typedef  vector<int>VI;#define REP (A, b) for (int i=a;i<b;i++)#define REP_ (A, b) for (int i=a;i<=b;i++)#define P pair<int,int>#define BUG printf ("===\n");#define PL (x) push_back (x)#define X First#define Y Second#define VI vector<int>#define REP (i,x,n) for (int i=x;i<n;i++)#define REP_ (i,x,n) for (int i=x;i<=n;i++)Const intmaxn=2100;Const intinf=999999;typedef Long LongLL;structnode{intx, y;intIdBOOL operator< (ConstNODE&AMP;T)Const{returny>t.y; }}P[MAXN];intF[MAXN];intD[MAXN];intLIS (intNint& POS) {intans=0; for(intI=0; i<n;i++) {d[i]=1; for(intj=0; j<i;j++)if(p[i].x>p[j].x&&p[i].y<p[j].y&&d[i]<d[j]+1) {f[i]=j; d[i]=d[j]+1; }if(Ans<d[i]) {//This place, update, here is not written in the above if, because even if the d[i] is not the last of the path, the final result will also be updated to hisAns=d[i];        Pos=i; }    }returnAns;}voidOutintx) {if(x==-1)return; Out (F[x]);printf("%d\n", p[x].id);}intMain () {intI=0; while(~scanf("%d%d", &p[i].x,&p[i].y)) {p[i].id=i+1;    i++; } cl (d,0); CL (f,-1);intN=i; Sort (p,p+n);//for (int i=0;i<n;i++) {//printf ("%d%d%d\n", p[i].x,p[i].y,p[i].id);//    }    printf("%d\n", LIS (n,i)); Out (i);return 0;}/*6008 13006000 2100500 20001000 40001100 30006000 20008000 14006000 12002000 1900*/

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

uva10131 is bigger Smarter? (classic dp, longest ascending subsequence, note save path section)

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.