解题思路:主要是利用动态数组来求出最大值
注意事项:
参考代码:
import java.util.Scanner; 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]; int[] dp = new int[n]; for(int i = 0; i < n; i++){ arr[i] = sc.nextInt(); dp[i] = 1; } int max = 0; for(int i = 1; i <= n-1; i++){ for(int j = i-1; j >= 0; j--){ if(arr[i] >= arr[j]){ dp[i] = Math.max(dp[i], dp[j]+1); } } if(dp[i] > max) max = dp[i]; } System.out.println(max); } } }
0.0分
2 人评分
十->二进制转换 (C语言代码)浏览:1395 |
人见人爱A+B (C语言代码)浏览:779 |
Tom数 (C语言代码)浏览:2010 |
点我有惊喜!你懂得!浏览:1435 |
C语言训练-谁家孩子跑最慢* (C语言代码)浏览:1507 |
C语言程序设计教程(第三版)课后习题10.2 (C语言代码)浏览:1066 |
大神老白 (C语言代码)浏览:603 |
C语言训练-素数问题 (C语言代码)浏览:1654 |
A+B for Input-Output Practice (IV) (C++代码)浏览:676 |
简单的a+b (C语言代码)浏览:681 |