题解 | #Redraiment的走法#

Redraiment的走法

https://www.nowcoder.com/practice/24e6243b9f0446b081b1d6d32f2aa3aa

#include <stdio.h>
#include <stdlib.h>


int max(int a,int b){
    return a>b?a:b;
}

int main() {
    int *high, n,num,*step_max;
    while (scanf("%d\n", &n) != EOF) { 
        high=(int*)malloc(n*sizeof(int));
        for(int i=0;i<n;i++){
            scanf("%d ",&high[i]);      //  载入高度数据
        }
        step_max=(int*)calloc(n, sizeof(int));
        step_max[n-1]=1;
        for(int i=n-1;i>=0;i--){        //  检查比较索引i
            int flag=0;
            for(int j=i+1;j<n;j++){
                
                if(high[j]>high[i]){
                    step_max[i]=max(step_max[j]+1,step_max[i]);
                    flag=1;
                }
                
            }
            if(flag==0){
                step_max[i]=1;
            }
        }
        int res=0;
        for(int i=0;i<n;i++){
            res=max(res,step_max[i]);
        }
        printf("%d\n",res);
    }
    return 0;
}

全部评论

相关推荐

06-07 12:20
新余学院 Java
点赞 评论 收藏
分享
今天 13:51
门头沟学院 Java
周五投的,流程今天结束
投递地平线等公司7个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务