标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 13643 Accepted Submission(s): 6011
Special Judge
1 #include<iostream> 2 #include<cstdio> 3 #include<algorithm> 4 using namespace std; 5 const int maxn = 1005; 6 struct node{ 7 int weight; 8 int speed; 9 int num; 10 }; 11 node p[maxn]; 12 int dp[maxn]; 13 bool cmp(node A,node B){ 14 if(A.weight != B.weight) return A.weight<B.weight; 15 else return A.speed>B.speed; 16 } 17 void solve(){ 18 int k = 1,x,y; 19 while(scanf("%d%d",&x,&y)!=EOF){ 20 p[k].weight = x; 21 p[k].speed = y; 22 p[k].num = k; 23 k++; 24 } 25 sort(p+1,p+k+1,cmp); 26 int ans = 0; 27 for(int i = k;i>=1; i--){ 28 dp[i] = 1; 29 for(int j = i; j<=k; j++){ 30 if(p[j].weight>p[i].weight&&p[j].speed<p[i].speed){ 31 dp[i] = max(dp[i],dp[j]+1); 32 } 33 } 34 ans = max(ans,dp[i]); 35 } 36 printf("%d\n",ans); 37 for(int i = 1; i<=k; i++){ 38 if(dp[i] == ans){ 39 printf("%d\n",p[i].num); 40 ans--; 41 } 42 if(ans == 0) break; 43 } 44 } 45 int main() 46 { 47 solve(); 48 return 0; 49 }
标签:
原文地址:http://www.cnblogs.com/littlepear/p/5386675.html