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

很屌的数据。。。

Posted by 20133820 at 2014-08-21 20:42:55 on Problem 1836
8
3 4 5 1 2 5 4 3
输出:2

附上代码

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

const double INF = 10000000;

double H[1005];
int n;

int max(int a, int b){
   return a>b?a:b;
}

int LIS(int a, int b){
    double dp[1005];
    fill(dp, dp+n, INF);
    int ans = 0;
    if(a<b){
        for(int i = a; i<=b; i++)
           *lower_bound(dp, dp+n, H[i]) = H[i];
        ans = lower_bound(dp, dp+n, INF) - dp;
    }
    else{
        for(int i = a; i>=b; i--)
           *lower_bound(dp, dp+n, H[i]) = H[i];
        ans = lower_bound(dp, dp+n, INF) - dp;
    }

    return ans;
}

int main(){
    scanf("%d",&n);
    memset(H, 0, sizeof(H));
    for(int i = 0; i<n; i++)
        scanf("%lf",&H[i]);

    //cout<<LIS(7,1)<<endl;
    int ans = 0;
    for(int i = 0; i<n; i++){
        int res = 0;
            res = LIS(0,i) + LIS(n-1, i) - 1;
            int res2 = 0;
            int k = i+1;
            while(k <n && H[i] != H[k++]);
            if(k != n)
                res2 = LIS(0,i) + LIS(n-1, k-1);
            res = max(res, res2);
        ans = max(ans, res);
    }

    printf("%d\n",n-ans);
    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