UVa 10131

 1 /*
 2 
 3 * 类似于最长递减子序列
 4 */
 5 #include<stdio.h>
 6 
 7 #include<string.h>
 8 #include<algorithm>
 9 using namespace std;
10 #define Max(x,y) (x>y?x:y)
11 #define max 1000+5
12 struct node{
13     int w,s,c;
14 }a[max];
15 int dp[max];
16 int pre[max];
17 
18 int cmp(node x,node y){
19     if(x.w<y.w){
20         return 1;
21     }
22     else if(x.w==y.w){
23         if(x.s>y.s){
24             return 1;
25         }
26     }
27     return 0;
28 }
29 
30 void printPath(int s){
31     printf("%d\n",a[s].c);
32     if(pre[s]){
33         printPath(pre[s]);
34     }
35 //    printf("%d\n",a[s].c);
36 }
37 
38 int main(){
39     int cnt;
40     for(cnt=1;scanf("%d%d",&a[cnt].w,&a[cnt].s)==2;a[cnt].c=cnt,cnt++);
41     sort(a+1,a+cnt,cmp);
42     memset(dp,0,sizeof(dp));
43     int m,mi,ans=0,mw,ms,ansi;
44     for(int i=cnt-1;i>0;i--){
45         m=0;mw=a[i].w;ms=a[i].s;
46         for(int j=i+1;j<cnt;j++){
47             if(a[j].w>mw&&a[j].s<ms&&dp[j]>m){
48                 m=dp[j];
49                 pre[i]=j;
50             }
51         }
52         dp[i]=m+1;
53         if(dp[i]>ans){
54             ans=dp[i];ansi=i;
55         }
56     }
57     printf("%d\n",ans);
58     printPath(ansi);
59 }

 

posted on 2013-07-18 19:43  Stomach_ache  阅读(120)  评论(0编辑  收藏  举报

导航