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

英语本来不好,example还是错的 更加难理解了,example答案是3啊,顺便给个n^2的代码

Posted by AllenYi at 2014-08-23 23:31:14 on Problem 1836
Source Code

Problem: 1836		User: AllenYi
Memory: 160K		Time: 63MS
Language: C++		Result: Accepted
Source Code


#include <iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int dp[1005],n;
int dp2[1005];
float height[1005];

void solve()
{
    dp[0]=1;
    for(int i=1;i<n;++i)
    {
        dp[i]=1;
        for(int j=0;j<i;++j)
        {
            if(height[j]<height[i])
                dp[i]=max(dp[i],dp[j]+1);
        }
    }
    for(int i=1;i<n;++i)
        dp[i]=max(dp[i],dp[i-1]);
    dp2[n-1]=1;
    for(int i=n-2;i>=0;--i)
    {
        dp2[i]=1;
        for(int j=n-1;j>i;--j)
        {
            if(height[j]<height[i])
                dp2[i]=max(dp2[i],dp2[j]+1);
        }
    }
    for(int i=n-2;i>=0;--i)
        dp2[i]=max(dp2[i],dp2[i+1]);
    int res=0x3f3f3f3f;
    for(int i=1;i<n;++i)
    {
        int tmp=n-dp[i-1]-dp2[i];
        if(res>tmp)
            res=tmp;
    }

    printf("%d\n",res);
}


int main()
{
    while(scanf("%d",&n)!=EOF)
    {
        for(int i=0;i<n;++i)
           scanf("%f",height+i);
        solve();
    }
    return 0;
}

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