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


/* 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:
10398877	panyanyany
2533
Accepted	172K	16MS	C++
1400B	2012-07-08 11:40:02

Test 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 MAXN	1009

#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;
}


你可能感兴趣的:(c,Date,url)