zoukankan      html  css  js  c++  java
  • 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
    ",a[s].c);
    32     if(pre[s]){
    33         printPath(pre[s]);
    34     }
    35 //    printf("%d
    ",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
    ",ans);
    58     printPath(ansi);
    59 }
  • 相关阅读:
    洛谷P3157 [CQOI2011]动态逆序对
    CDQ分治
    快速数论变换(NTT)
    洛谷P3338 [ZJOI2014]力
    洛谷 P1919 A*B Problem升级版
    0-1分数规划
    洛谷P4593 [TJOI2018]教科书般的亵渎
    拉格朗日插值
    20180912-3 词频统计
    20190912-1 每周例行报告
  • 原文地址:https://www.cnblogs.com/Stomach-ache/p/3703225.html
Copyright © 2011-2022 走看看