当前所在位的最长上升子序列只和前面一个字符有关
#include <iostream> #include <algorithm> using namespace std; int s[10]; int len; int main() { int n = 8; int arr[9] = {0,7,8,9,6,5,4,3,2}; s[1] = 1; len = 1; } int pa(int *arr,int n) { for(int i=2;i<=n; ++i) { if(arr[i] > s[len]) s[++len] = arr[i]; else { int pos = lower_bound(s, s+len, arr[i]) - s; s[pos] = arr[i]; } }
//路径输出
int d[8];
for(i=n; i>=0 ;--i)
{
if(pos[i] == len)
d[len--] = arr[i];
}
return len;
}