标签:
LIS,最长递增子序列
1 #include <iostream> 2 #include <cstdlib> 3 4 using namespace std; 5 6 int LIS(int* arr, int len) { 7 if (arr == NULL || len < 1) return 0; 8 int LIS[len] = {0}; 9 int mlen = 0; 10 for (int i=0; i<len; i++) { 11 LIS[i] = 1; 12 for (int j = 0; j < i; j++) { 13 if (arr[j] < arr[i] && LIS[i] < LIS[j] + 1) { 14 LIS[i] = LIS[j] + 1; 15 } 16 } 17 if (LIS[i] > mlen) { 18 mlen = LIS[i]; 19 } 20 } 21 return mlen; 22 } 23 24 25 int main() { 26 int arr[] = {1, -1, 2, -3, 4, -5, 6, -7}; 27 int len = sizeof(arr) / sizeof(arr[0]); 28 cout<<LIS(arr, len)<<endl; 29 system("pause"); 30 return 0; 31 }
LCS,最长公共子序列
标签:
原文地址:http://www.cnblogs.com/lailailai/p/4309394.html