POJ 2533 Longest Ordered Subsequence(DP 동적 계획)

#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
", result); return 0; }

좋은 웹페이지 즐겨찾기