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?