动规基础,最长上升子序列

来源:互联网 发布:plc步进电机编程实例 编辑:程序博客网 时间:2024/04/20 16:13
package com.ohere;public class LongestIncreasingSubSet {public static void main(String[] args) {// TODO Auto-generated method stubint[] test = {1,7,3,5,9,4,8,9,10};longestString(test);}public static void longestString(int [] str){int [] maxLength = new int[str.length];maxLength[0] = 1;for (int i = 1; i < str.length; i++){int tempLen = 0;for (int j = 0; j < i;j++){if (str[j] < str[i]){tempLen = Math.max(tempLen, maxLength[j]);}}maxLength[i] = tempLen + 1;}int result = 0;for (int x: maxLength){result = Math.max(result, x);}System.out.println(result);}}

0 0