标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 9871 Accepted Submission(s): 4374
Special Judge
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<stdlib.h> #include<queue> #include<stack> #include<algorithm> #define LL __int64 using namespace std; const int MAXN=10000+50; const int INF=0x3f3f3f3f; const double EPS=1e-9; int dir4[][2]={{0,1},{1,0},{0,-1},{-1,0}}; int dir8[][2]={{0,1},{1,1},{1,0},{1,-1},{0,-1},{-1,-1},{-1,0},{-1,1}}; int dir_8[][2]={{-2,1},{-1,2},{1,2},{2,1},{2,-1},{1,-2},{-1,-2},{-2,-1}}; struct node { int w; int s; int index; bool operator<(const node A)const { if(w!=A.w) return w<A.w; return s>A.s; } }a[MAXN]; int dp[MAXN],pre[MAXN]; void print(int p) { if(pre[p]!=-1) print(pre[p]); printf("%d\n",a[p].index); } int main() { int weight,speed,cnt=0; while(scanf("%d %d",&weight,&speed)!=EOF) { a[cnt].w=weight; a[cnt].s=speed; a[cnt].index=cnt+1; cnt++; } sort(a,a+cnt); memset(dp,0,sizeof(dp)); memset(pre,-1,sizeof(pre)); dp[0]=1; int id,maxn=-INF; for(int i=1;i<cnt;i++) { dp[i]=1; for(int j=0;j<i;j++) { if(a[i].w!=a[j].w && a[i].s<a[j].s) { if(dp[j]+1>dp[i]) { dp[i]=dp[j]+1; pre[i]=j; } } } if(dp[i]>maxn) { maxn=dp[i]; id=i; } } printf("%d\n",dp[id]); print(id); return 0; }
标签:
原文地址:http://www.cnblogs.com/clliff/p/4250622.html