import java.util.*; public class Main { public static void main(String[] args){ Scanner in = new Scanner(System.in); while(in.hasNext()){ int trees = Integer.parseInt(in.nextLine().trim()); int[] peaches = new int[trees]; for (int i = 0; i < trees; i++) { peaches[i] = Integer.parseInt(in.nextLine()); } int[] revP = new int[trees]; for(int i = 0; i < trees; i++){ revP[i] = peaches[i]; } Arrays.sort(revP); int len1 = peaches.length; int len2 = revP.length; int[][] dp = new int[len1+1][len2+1]; for(int i = 0; i < len1; i++){ for(int j = 0; j < len2; j++){ if(peaches[i] == revP[j]){ dp[i+1][j+1] = dp[i][j] + 1; }else{ dp[i+1][j+1] = Math.max(dp[i][j+1], dp[i+1][j]) > dp[i][j] ? Math.max(dp[i][j+1],dp[i+1][j]) : dp[i][j]; } } } System.out.println(dp[len1][len2]); } in.close(); } } AC
点赞 评论

相关推荐

09-29 11:19
门头沟学院 Java
点赞 评论 收藏
分享
牛客网
牛客企业服务