好久没有发博了,最近看了动归和背包问题,有点看不下去,所以先从简单的题目入手。
这个是裸LIS的题目。(n²)
接下来有个复杂点的题目:poj 1836,同一个算法
#define LOCAL #include <stdio.h> #include <string.h> #include <stdlib.h> #define MAXN 1000 + 10 int value[MAXN]; int longestSub[MAXN]; int main() { #ifdef LOCAL freopen("C:\\Users\\Administrator\\Desktop\\Temp\\ACMTempIn.txt", "r", stdin); //freopen("C:\\Users\\Administrator\\Desktop\\Temp\\ACMTempOut.txt", "w", stdout); #endif int cases; int i,j,max; while(scanf("%d", &cases) != EOF) { memset(longestSub, 0, sizeof(longestSub)); memset(value, 0, sizeof(value)); for(i = 0; i < cases; i++) { max = 0; scanf("%d", &value[i]); longestSub[i] = 1; for(j = 0; j < i; j++) { if(value[j] < value[i] && max < longestSub[j]) { max = longestSub[j]; } longestSub[i] = max + 1; } } max = 0; for(i = 0; i < cases; i++) if(max < longestSub[i]) max = longestSub[i]; printf("%d\n", max); } return 0; }