#include<iostream>
}
#include <stdio.h> #include <algorithm> using namespace std; int solve(int *A, int n) { int loc[n]; int glo; loc[0] = glo = 1; for (int i = 1; i < n; i++) { int ma = 1; for (j = i-1; j >= 0; j--) { if (A[i] >= A[j]) ma = max(ma, loc[j]); } loc[i] = ma + 1; glo = max(glo, loc[i]); } return glo; } int main() { int n; int a[n]; //输入啊a[n] printf("最长非降序列长度为: %d\n", solve(a, n)); return 0; }
#include <stdio.h> void Update(int * B,int len,int d) { while(len>1) { if ( d>=B[len-1] ) { B[len] = d; return ; } --len; } B[1] = d; } int LIS(int d[], int n) { int * B = new int[n+1]; memset(B,0x7fffffff,(n+1)*sizeof(int)); B[1] = d[0]; int len = 1; for ( int i=1;i<n;++i ) { if ( d[i]<B[len] ) { Update(B,len,d[i]); } else { B[++len] = d[i]; } } return len; } int main() { int d[6] = {5,3,4,8,6,7}; printf("%d\n",LIS(d,6)); return 0; }