题解 | #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; }