题解 | #Redraiment的走法#

Redraiment的走法

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

import java.util.*;
import java.io.*;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
       BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        try {
            String count = br.readLine();
            String str = br.readLine();
            int[] dp = new int[Integer.valueOf(count)+1];
             int max=0;
            for (int i = 1; i <= Integer.valueOf(count); i++) {
                dp[i]=1;
                for (int j = 1; j < i; j++) {
                    if(Integer.valueOf(str.split(" ")[j-1]) < Integer.valueOf(str.split(" ")[i-1])){
                        dp[i]=Math.max(dp[i],dp[j]+1);
                    }
                }
                max=Math.max(dp[i],max);
            }
            System.out.println(max);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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