标签:
问题描述:对于2,5,3,1,9,4,6,8,7,找出最长上升子序列的个数
最长上升子序列定义:
对于i<j i,j∈a[0...n] 满足a[i]<a[j]
void Main() { DP_LIS(); Console.WriteLine(dpArr); } static int[] arr = new int[9]{2,5,3,1,9,4,6,8,7}; static int n = 9; static int[] dpArr = new int[9]; static void DP_LIS(){ for(var i= 0;i < n; i++){ dpArr[i] = 1; for(var j = 0;j < i; j++){ if(arr[j]<arr[i] && dpArr[i] < dpArr[j] + 1){ dpArr[i] = dpArr[j]+1; } } } }
标签:
原文地址:http://blog.csdn.net/lan_liang/article/details/46680405