Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

一个水题也Wa 了很久。。说一下我的问题。。

Posted by SCSE10_Candybox at 2011-07-22 21:36:48 on Problem 1836
1、两遍lcs
2、枚举顶点

注意:
1、是可以看到无穷远处,就是对于新的数列b: b1<b2<b3....<bi bi+1>bi+2.... 两头必须也强小于
2、中间可能有一个或者两个顶点,两个顶点的情况有可能顶点在a数组里面不挨着。

给出代码:
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
const int NN=2000;
double a[NN];
int lcsl[NN],lcsr[NN],ans,n;
int main()
{
    int tmp;
    scanf("%d",&n);
    memset(a,0,sizeof(a));
    memset(lcsl,-1,sizeof(lcsl));
    memset(lcsr,-1,sizeof(lcsr));
    for (int i=0;i<n;++i) scanf("%lf",&a[i]);
    lcsl[0]=1;
    for (int i=1;i<n;++i)
    {
        for (int j=0;j<i;++j)
            if (lcsl[j]+1>lcsl[i] && a[j]<a[i])
               lcsl[i]=lcsl[j]+1;
        if (lcsl[i]==-1) lcsl[i]=1;
    }
    lcsr[n-1]=1;
    for (int i=n-2;i>=0;--i)
    {
        for (int j=n-1;j>i;--j)
            if (lcsr[j]+1>lcsr[i] && a[i]>a[j])
               lcsr[i]=lcsr[j]+1;
        if (lcsr[i]==-1) lcsr[i]=1;
    }
    ans=-1;
    for (int i=0;i<n-1;++i)
        for (int j=i+1;j<n;++j)
            if (lcsl[i]+lcsr[j]>ans)
               ans=lcsl[i]+lcsr[j];
    for (int i=0;i<n;++i)
        if (lcsl[i]+lcsr[i]-1>ans)
           ans=lcsl[i]+lcsr[i]-1;
    printf("%d\n",n-ans);
    //system("pause");
} 

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator