题解 | #Redraiment的走法#

Redraiment的走法

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

抄袭大佬,用的是动态规划的思路

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            int n = sc.nextInt();
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = sc.nextInt();
            }
            int[] dp = new int[n];
            for (int i = 1; i < n; i++) {
                for (int j = 0; j < i; j++) {
                    if (arr[j] < arr[i]) {
                        dp[i] = Math.max(dp[i], dp[j] + 1);
                    }
                }
            }
            Arrays.sort(dp);
            System.out.println(dp[n- 1] + 1);
        }
        sc.close();
    }
}
全部评论

相关推荐

评论
点赞
3
分享

创作者周榜

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