贪心怎么不行?#1 WA了

B3637 最长上升子序列

czh2 @ 2024-06-08 10:13:31

#include<stdio.h>
int f(int *a,int n,int b){
    int l=0,r=n,mid=(l+r)/2;
    while(l<=r){
        if(a[mid]<=b){
            l=mid+1;
        }else{
            r=mid-1;
        }
        mid=(l+r)/2;
    }
    return l;
}
int main(){
    int n,len=1;
    scanf("%d",&n);
    int s[n],low[n];
    scanf("%d",&s[0]);
    low[0]=s[0];
    for(int i=1;i<n;i++){
        scanf("%d",&s[i]);
        if(s[i]>low[len-1]){
            low[len++]=s[i];
        }else if(s[i]<low[len-1]){
            low[f(low,len-1,s[i])]=s[i];
        }
    }
    printf("%d",len);
    return 0;
}

by WYZ20030051 @ 2024-06-08 10:48:58

@czh2 请给出证明


|