题解 | #Redraiment的走法#
Redraiment的走法
https://www.nowcoder.com/practice/24e6243b9f0446b081b1d6d32f2aa3aa
import java.util.*; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); ArrayList<Integer> list = new ArrayList<>(); int max = 1; for (int i = 0; i < n; i++) { list.add(sc.nextInt()); } int[] dp = new int[n]; for (int i = 0; i < n; i++) { dp[i] = 1; } for (int i = 0; i < n; i++) { for (int j = 0; j < i; j++) { if (list.get(j) < list.get(i)) { dp[i] = Math.max(dp[j] + 1, dp[i]); if (max < dp[i]) { max = dp[i]; } } } } System.out.println(max); } }