最长递增子序列

这又是一个动态规划的问题,可以使用一个数组保存长度为n的子序列的最小的值

int *len = (int *)malloc(sizeof(int) *n);

if (!len) {

  printf("out of sapce\n");

  exit(-1);

  }

  len[0] = a[0];

  count = 1;

  for (i = 1; i < n; i++) {

    for (j = 0; j < count; j++) {

      if (a[i] <= len[j]) {

        break;

      }

  }

  if (j == count) {

    len[count++] = a[j];

  }  else {

    len[j] = a[i];

  }

  return count;

  }

原文地址:https://www.cnblogs.com/chonghui1001/p/2193110.html