解题思路:主要是利用动态数组来求出最大值
注意事项:
参考代码:
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 人评分
WU-格式化数据输出 (C++代码)浏览:1212 |
剪刀石头布 (C++代码)浏览:1711 |
分糖果 (C语言代码)浏览:920 |
理财计划 (C语言代码)浏览:467 |
1231题解(注意理解“输入多个测试实例”)浏览:788 |
C语言程序设计教程(第三版)课后习题5.4 (C语言代码)浏览:468 |
C语言程序设计教程(第三版)课后习题4.9 (C语言代码)浏览:560 |
C语言程序设计教程(第三版)课后习题8.2 (C++代码)浏览:661 |
C语言训练-求素数问题 (C语言代码)浏览:615 |
A+B for Input-Output Practice (I) (C++代码)浏览:629 |