标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 9069 Accepted Submission(s):
4022
Special Judge
1 #include<iostream> 2 #include<stdio.h> 3 #include<algorithm> 4 using namespace std; 5 int b[1001]; 6 int a[1001]; 7 int c[1001]; 8 struct node 9 { 10 int w; 11 int v; 12 int sign; 13 14 } s[1001]; 15 int cmp(node x, node y) 16 { 17 if(x.w==y.w) 18 return x.v>y.v; 19 return x.w<y.w; 20 } 21 int main() 22 { 23 int i,j,flag=-1,k=1,Max=0; 24 while(scanf("%d %d",&s[k].w, &s[k].v)!=EOF) 25 { 26 s[k].sign=k; 27 k++; 28 } 29 sort(s,s+k,cmp); 30 for(i=1; i<k; i++) 31 { 32 a[i]=1; 33 b[i]=-1; 34 for(j=i-1; j>=1; j--) 35 { 36 if(s[i].w>s[j].w && s[i].v<s[j].v && a[j]+1>a[i]) 37 { 38 a[i]=a[j]+1; 39 b[i]=j; 40 } 41 } 42 if(a[i]>Max) 43 { 44 Max=a[i]; 45 flag=i; 46 } 47 } 48 printf("%d\n",Max); 49 int t=0; 50 while(flag!=-1) 51 { 52 c[t]=flag; 53 flag=b[flag]; 54 t++; 55 } 56 for(i=t-1; i>=0; i--) 57 printf("%d\n",s[c[i]].sign); 58 return 0; 59 }
标签:
原文地址:http://www.cnblogs.com/lxm940130740/p/3871099.html