#include <stdio.h>
int seq[1001];
//lenOfLOSWithTai[i]表示已seq[i]为结尾的最长有序子序列的长度
int lenOfLOSWithTail[1001];//length of longest ordered sequence with tail
int main(){
int lenOfSeq;
scanf("%d", &lenOfSeq);
int i;
for (i = 0; i < lenOfSeq; i++)
scanf("%d", &seq[i]);
int result = 0;
for(i = 0; i < lenOfSeq; i++){
lenOfLOSWithTail[i] = 1;
int j;
for (j = 0; j < i; j++)
if (seq[i] > seq[j] && lenOfLOSWithTail[j] + 1 > lenOfLOSWithTail[i])
lenOfLOSWithTail[i] = lenOfLOSWithTail[j] + 1;
if (lenOfLOSWithTail[i] > result)
result = lenOfLOSWithTail[i];
}
printf("%d\n", result);
return 0;
}
POJ 2533 Longest Ordered Subsequence (DP动态规划)
最新推荐文章于 2021-07-25 22:06:01 发布