标签:style blog io ar color sp for div log
最长递增子序列
#include<stdio.h> #include<stdlib.h> #include<time.h> #include<string.h> #define N 4 int solve(int *array, int n) { int *dp = (int *)malloc(n * sizeof(int)); int i; int j; int result; bzero((void *)dp, n * sizeof(int)); dp[0] = 1; for(i = 1; i < n; i++) { *(dp + i) = *(dp + i - 1); for(j = 0; j < i; j ++) { if(*(array + i) > *(array + j)) { *(dp + i) = (*(dp + i) < *(dp + j) + 1) ? (*(dp + j) + 1) : *(dp + i); } } } result = *(dp + n -1); free(dp); return result; } int main(char ** args) { srand((unsigned)time(NULL)); int *array = (int *)malloc(N * sizeof(int)); for(int i = 0; i < N; i++) { *(array + i) = rand() % N; printf("%d\t", *(array + i)); } int ret = solve(array, N); printf("\nresult:%d\n", ret); free(array); return 0; }
标签:style blog io ar color sp for div log
原文地址:http://www.cnblogs.com/igloo1986/p/4164690.html