【最大上升子序列+经典题】北大 poj 2533 Longest Ordered Subsequence

来源:互联网 发布:多功能网络电力仪表 编辑:程序博客网 时间:2024/05/21 07:39


/* THE PROGRAM IS MADE BY PYY *//*----------------------------------------------------------------------------//    Copyright (c) 2012 panyanyany All rights reserved.    URL   : http://poj.org/problem?id=2533    Name  : 2533 Longest Ordered Subsequence    Date  : Sunday, July 8, 2012    Time Stage : half an hour    Result:10398877panyanyany2533Accepted172K16MSC++1400B2012-07-08 11:40:02Test Data :Review ://----------------------------------------------------------------------------*/#include <stdio.h>#include <stdlib.h>#include <string.h>#include <math.h>#include <vector>#include <algorithm>#include <iostream>#include <queue>#include <set>#include <string>using namespace std ;#define MEM(a, v)        memset (a, v, sizeof (a))    // a for address, v for value#define max(x, y)        ((x) > (y) ? (x) : (y))#define min(x, y)        ((x) < (y) ? (x) : (y))#define INF     (0x3f3f3f3f)#define MAXN1009#define L(x)((x)<<1)#define R(x)(((x)<<1)|1)#define M(x, y)(((x)+(y)) >> 1)#define DB    //int dpInc[MAXN], a[MAXN];int LIS(int a[], int n){int i, j;for (i = 0; i < n; ++i){dpInc[i] = 1;for (j = 0; j < i; ++j){if (a[j] < a[i])dpInc[i] = max(dpInc[i], dpInc[j] + 1);}}j = 0;for (i = 0; i < n; ++i)j = max(j, dpInc[i]);return j;}int main(){int i, n;while (scanf("%d", &n) != EOF){for (i = 0; i < n; ++i)scanf("%d", a+i);printf("%d\n", LIS(a, n));}return 0;}


原创粉丝点击