题解 | #Redraiment的走法#
Redraiment的走法
https://www.nowcoder.com/practice/24e6243b9f0446b081b1d6d32f2aa3aa
import java.util.*; // mark 一下 // 最长上升子序列问题 // each j < i && array[j] < array[i] -> dp[i] = Math.max(dp[i], dp[j] + 1); public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); while (in.hasNextInt()) { int n = in.nextInt(); int[] array = new int[n + 1]; int[] dp = new int[n + 1]; for (int i = 1; i < n + 1; i++) { array[i] = in.nextInt(); dp[i] = 1; } int ans = 0; for (int i = 1; i < n + 1; i++) { for (int j = 1; j < i; j++) { if (array[i] > array[j]) { dp[i] = Math.max(dp[j] + 1, dp[i]); } } ans = Math.max(ans, dp[i]); } System.out.println(ans); } } }