1 /* 2 3 * 类似于最长递减子序列 4 */ 5 #include6 7 #include 8 #include 9 using namespace std;10 #define Max(x,y) (x>y?x:y)11 #define max 1000+512 struct node{13 int w,s,c;14 }a[max];15 int dp[max];16 int pre[max];17 18 int cmp(node x,node y){19 if(x.w y.s){24 return 1;25 }26 }27 return 0;28 }29 30 void printPath(int s){31 printf("%d\n",a[s].c);32 if(pre[s]){33 printPath(pre[s]);34 }35 // printf("%d\n",a[s].c);36 }37 38 int main(){39 int cnt;40 for(cnt=1;scanf("%d%d",&a[cnt].w,&a[cnt].s)==2;a[cnt].c=cnt,cnt++);41 sort(a+1,a+cnt,cmp);42 memset(dp,0,sizeof(dp));43 int m,mi,ans=0,mw,ms,ansi;44 for(int i=cnt-1;i>0;i--){45 m=0;mw=a[i].w;ms=a[i].s;46 for(int j=i+1;j mw&&a[j].s m){48 m=dp[j];49 pre[i]=j;50 }51 }52 dp[i]=m+1;53 if(dp[i]>ans){54 ans=dp[i];ansi=i;55 }56 }57 printf("%d\n",ans);58 printPath(ansi);59 }