【最长下降子序列+有难度】北大 poj 1836 Alignment

来源:互联网 发布:泰拉瑞亚安卓联机软件 编辑:程序博客网 时间:2024/04/27 19:21


/* THE PROGRAM IS MADE BY PYY *//*----------------------------------------------------------------------------//    Copyright (c) 2012 panyanyany All rights reserved.    URL   : http://poj.org/problem?id=1836    Name  : 1836 Alignment    Date  : Sunday, July 8, 2012    Time Stage : one hour    Result:10399094panyanyany1836Accepted196K63MSC++1758B2012-07-08 12:37:2910399074panyanyany1836Wrong AnswerC++1727B2012-07-08 12:34:3210399061panyanyany1836Wrong AnswerC++1733B2012-07-08 12:31:5710398987panyanyany1836Wrong AnswerC++1726B2012-07-08 12:04:20Test Data :Review :这题跟《合唱队形》是差不多的,只不过合唱队形要求只有一个至高点,而这里却可以有两个一样高的至高点。合唱队形是根据某个人的身高,来求他两边的人数。而这题,则是根据某个人某一边的人数,加上另一个人另一边的人数(两人的人数不能重合)。具体的话,可以看下面的链接,有图有真象:http://cavenkaka.iteye.com/blog/1542421//----------------------------------------------------------------------------*/#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 DesLeft[MAXN], DesRight[MAXN];double a[MAXN];enum { LEFT, RIGHT };int LDesS(int dp[], double a[], int n, int dir = RIGHT){int beg, end, step, i, j;if (RIGHT == dir){beg = 0;end = n;step = 1;}else{beg = n - 1;end = -1;step = -1;}for (i = beg; i != end; i += step){dp[i] = 1;for (j = beg; j != i; j += step){if (a[i] > a[j])dp[i] = max(dp[i], dp[j] + 1);}}return dir;}int main(){int i, j, n, k;while (scanf("%d", &n) != EOF){for (i = 0; i < n; ++i)scanf("%lf", a+i);LDesS(DesLeft, a, n);LDesS(DesRight, a, n, LEFT);k = 0;for (i = 0; i < n; ++i){for (j = i + 1; j < n; ++j)k = max(k, DesLeft[i] + DesRight[j]);}printf("%d\n", n - k);}return 0;}


原创粉丝点击