现在的位置: 首页 > 综合 > 正文

BNU 看风景 27585

2019年02月25日 ⁄ 综合 ⁄ 共 752字 ⁄ 字号 评论关闭

题目链接~~>

做题感悟:比赛时一看这题就知道得用动态规划做,所以就下意识的跳过了难过,一直在看绝对值排序那题,经过这场比赛总结出不能认为一个题有思路就一直搞,必要时切一下题也是很好的。

解题思路:从0~n枚举,把一个序列分成两部分,分别进行单调递增子序列,总长度减去两部分之和就是要减去的人的个数。

代码:

#include<stdio.h>
#include<iostream>
#include<map>
#include<string>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<queue>
#include<algorithm>
using namespace std ;
const int MX = 1005 ;
int g[MX],b[MX] ;
int main()
{
    int n ;
    while(~scanf("%d",&n))
    {
        for(int i=0 ;i<n ;i++)
            scanf("%d",&g[i]) ;
        int max=-1,x,r=0 ;
        for(int i=-1 ;i<n ;i++)
        {
            r=0 ;
            if(i!=-1)
               b[r++]=g[0] ;
            for(int j=1 ;j<=i ;j++)
               if(b[r-1]<g[j])
                      b[r++]=g[j] ;
               else
               {
                      x=lower_bound(b,b+r,g[j])-b ;
                      b[x]=g[j] ;
               }
             int p=0 ;
             if(i!=n-1)
                   b[p++]=g[n-1] ;
             for(int j=n-2 ;j>i ;j--)
               if(b[p-1]<g[j])
                   b[p++]=g[j] ;
               else
               {
                   x=lower_bound(b,b+p,g[j])-b ;
                   b[x]=g[j] ;
               }
              max=max > p+r ? max : p+r ;
         }
         printf("%d\n",n-max) ;
    }
    return 0 ;
}

 

抱歉!评论已关闭.