题解 | #Redraiment的走法#

Redraiment的走法

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

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNext()) { 
            int n = in.nextInt();
            int[] shu = new int[n];
            for(int i =0;i<n;i++){
                shu[i] = in.nextInt();
            }
            int[] dp = new int[n];
            dp[0] = 1;
            int sum = 0;
            for(int i =1;i<n;i++){
                dp[i] = 1;
                for(int j=0;j<i;j++){
                    if(shu[i]>shu[j]) dp[i]=Math.max(dp[i],dp[j]+1);
                }
                sum = Math.max(dp[i],sum);
            }
            System.out.println(sum);
        }
    }
}

全部评论

相关推荐

评论
点赞
收藏
分享
牛客网
牛客企业服务