#include <cstdio> #include <iostream> #include <algorithm> #include <queue> #include <stack > #include <climits> #include <cstring> #include <cmath> #include <map> #include <set># Define INF 100000000using namespace std;struct node{int x, y;}; Node A[1005];int n;int ma[1005][1005];int dp[1005];void print (int max,int q) {if (max = = 1) {printf ("%d\n", q+1); return;} printf ("%d\n", q+1); for (int i = 0;i < n;i++) {if (Ma[q][i] && dp[i] = = max-1) {print (max-1,i); break;}}} int Fun (node &x,node &y) {if (x.x < y.x && x.y > Y.y) return 1;return 0;} int dfs (int cur) {int& ret = dp[cur];if (Ret > 0) return ret;ret = 1;for (int i = 0;i < n;i++) {if (Ma[cur][i]) {ret = Max (Dfs (i) +1,ret);}} return ret;} int main () {while (scanf ("%d%d", &a[n].x,&a[n].y)!=eof) n++;memset (ma,0,sizeof (MA)); for (int i = 0;i < n;i++) { for (int j = 0;j < n;j++) {if (Fun (a[i],a[j]) > 0) {ma[i][j] = 1;}}} for (int i = 0;i < n;i++) {DFS (i);} int Maxn;iNT max = -1;for (int i = 0;i < n;i++) {if (Dp[i] > max) {maxn = I;max = Dp[i];} cout << Max << Endl;print (M AX,MAXN); return 0;}
UVA 10131 is bigger Smarter? Dag longest route plus path restore