UVa 10131-is bigger Smarter?

Source: Internet
Author: User

Title: Some people think that the elephant's weight and intelligence have a certain positive correlation, now give you some data, find a longest counter-example sequence.

Analysis: Dp,lis, drunken ascending sub-sequence. The maximum descending sub-sequence of s is calculated for the W sort, and the storage path precursor, DFS output.

Description: Read the EOF before processing.

#include <algorithm> #include <iostream> #include <cstdlib> #include <cstring> #include < Cstdio> #include <cmath>using namespace std;typedef struct enode{int id,w,s;} Elephant;elephant E[1001];int cmp (Elephant A, elephant b) {if (A.W = B.W) {if (A.S = = B.S) return a.id < B.id;else retur n a.s > b.s;} else return A.W < B.W;} int f[1001],p[1001];void output (int s,int d) {if (p[s] = = s) {printf ("%d\n%d\n", d,e[s].id); return;} else {output (P[s], d+1);p rintf ("%d\n", E[s].id);}} int main () {int count = 0;while (~scanf ("%d%d", &e[count].w,&e[count].s)) {e[count].id = Count+1;count + +;} Sort (E, E+count, CMP); int spa = 0;for (int i = 0; i < count; + + i) {f[i] = 1; P[i] = i;for (int j = 0; J < i; + + j) if (E[i].w > E[J].W && e[i].s < E[J].S && F[i] < f[j]+1 ) {F[i] = f[j]+1; P[i] = j;} if (F[spa] < f[i]) spa = i;}    Output (Spa, 1); return 0;}


UVa 10131-is bigger Smarter?

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.