题解 | #和之前的合唱队题类似,动态规划#
Redraiment的走法
https://www.nowcoder.com/practice/24e6243b9f0446b081b1d6d32f2aa3aa
import java.util.Scanner; import java.util.Scanner; import java.util.Arrays; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); while (in.hasNext()){ int nums = in.nextInt(); int[] wood=new int[nums]; for (int i = 0; i <nums ; i++) { wood[i]=in.nextInt(); } int[] left=new int[nums];//记录每个数其左边的最长递增字串数, left[0]=1; for (int i = 1; i <nums ; i++) { left[i]=1; for (int j = 0; j <i ; j++) { if (wood[i]>wood[j]) { left[i] = Math.max(left[i],left[j]+1); } } } Arrays.sort(left); System.out.println(left[nums-1]); } } }