zoj1108
来源:互联网 发布:mysql按月分区表 编辑:程序博客网 时间:2024/05/22 00:26
#include<iostream>#include<stdio.h>#include<string.h>#include<algorithm>#include<limits.h>#include<stack>#include<cmath>#define MAX 1010using namespace std;struct mose{ int w,s,x; int len; mose(){}; mose(int w,int s,int x):w(w),s(s),x(x) {}; bool operator <(const mose b)const { if( w<b.w) return true; else if(w==b.w) { return s>=b.s; } return false; }}moses[MAX];int dp[MAX];int main(){ int n=0,w,s,x,i,j; while(~scanf("%d%d",&w,&s)) { moses[n]=mose(w,s,n+1); n++; } sort(moses,moses+n); moses[0].len=1; dp[0]=0; int ans=0; for( i=1;i<n;i++) { int maxi=i; moses[i].len=0; for(j=0;j<n;j++) { if(moses[i].s<moses[j].s&&moses[i].w>moses[j].w) { if(moses[j].len>=moses[maxi].len) maxi=j; } } if(maxi==i) moses[i].len=1; else moses[i].len=moses[maxi].len+1; if(moses[ans].len<moses[i].len) ans=i; dp[i]=maxi; } stack<int>st; st.push(moses[ans].x); while(dp[ans]!=ans) { st.push(moses[dp[ans]].x); ans=dp[ans]; } printf("%d\n",st.size()); while(!st.empty()) { printf("%d\n",st.top()); st.pop(); }}