标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 13894 Accepted Submission(s): 6133
Special Judge
#include<iostream> #include<cstdio> #include<cstring> #include<queue> #include<algorithm> using namespace std; #define INF 99999999 struct Node { int num; int weight; int speed; } mouse[1005]; int dp[1005]; int father[1005]; bool cmp(Node a,Node b) { if(a.weight<b.weight) return 1; else if(a.weight==b.weight&&a.speed>b.speed) return 1; return 0; } /* void find(int j) { if(father[j]==j) { cout<<mouse[j].num<<endl; return; } if(father[j]!=j) { find(father[j]); cout<<mouse[j].num<<endl; } } */ int main() { int cnt=1; while(scanf("%d%d",&mouse[cnt].weight,&mouse[cnt].speed)!=EOF) { mouse[cnt].num=cnt; dp[cnt]=1; father[cnt]=cnt; cnt++; } sort(mouse+1,mouse+cnt,cmp); for(int i=2; i<=cnt-1; i++) for(int j=1; j<i; j++) { if(mouse[i].weight>mouse[j].weight&&mouse[i].speed<mouse[j].speed&&dp[j]+1>dp[i]) { dp[i]=dp[j]+1; father[i]=j; } } int flag; int ans=0; for(int i=1;i<=cnt-1;i++) if(dp[i]>ans) { ans=dp[i]; flag=i; } printf("%d\n",ans); int num[1005]; for(int i=1;i<=ans;i++) { num[i]=mouse[flag].num; flag=father[flag]; } for(int i=ans;i>=1;i--) printf("%d\n",num[i]); return 0; }
标签:
原文地址:http://www.cnblogs.com/jasonlixuetao/p/5496892.html