标签:
import java.util.Scanner; public class Main { public int[][] matrix(int[] num){ int length = num.length; int[][] matrix = new int[length + 1][length]; for(int i = 0; i < length; i ++){ matrix[i + 1][i] = 1; matrix[0][i] = 1; } for(int i = length - 2; i >= 0; i --){ for(int j = i + 2; j < length + 1; j ++){ if(num[i] >= num[j - 1]){ matrix[j][i] = matrix[0][j - 1] + 1; }else{ matrix[j][i] = 1; } matrix[0][i] = matrix[0][i] < matrix[j][i] ? matrix[j][i] : matrix[0][i]; } } return matrix; } public static void main(String args[]){ Scanner sc = new Scanner(System.in); String str = sc.nextLine(); String[] temp = str.split(" "); int length = temp.length; int[] num = new int[length]; int[] minOs = new int[length + 1]; int minNum = 0; for(int i = 0; i < length; i ++){ num[i] = Integer.parseInt(temp[i]); } int[][] matrix = new Main().matrix(num); int max = 1; for(int i = 0; i < length; i ++){ max = max < matrix[0][i] ? matrix[0][i] : max; } for(int i = 0; i < length; i ++){ for(int j = 0; j < length; j ++){ if(minOs[j] ==0 || num[i] <= minOs[j]){ minOs[j] = num[i]; break; } } } for(int i = 0; i < minOs.length; i ++){ if(minOs[i] == 0){ minNum = i; break; } } System.out.println(max); System.out.println(minNum); } }
标签:
原文地址:http://www.cnblogs.com/watchfree/p/5769100.html