BNU 看风景 27585
【摘要】 题目链接~~>
做题感悟:比赛时一看这题就知道得用动态规划做,所以就下意识的跳过了,一直在看绝对值排序那题,经过这场比赛总结出不能认为一个题有思路就一直搞,必要时切一下题也是很好的。
解题思路:从0~n枚举,把一个序列分成两部分,分别进行单调递增子序列,总长度减去两部分之和就是要减去的人的个数。
代码:
#include<stdio.h>#inclu...
做题感悟:比赛时一看这题就知道得用动态规划做,所以就下意识的跳过了,一直在看绝对值排序那题,经过这场比赛总结出不能认为一个题有思路就一直搞,必要时切一下题也是很好的。
解题思路:从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 ;
-
}
文章来源: blog.csdn.net,作者:Linux猿,版权归原作者所有,如需转载,请联系作者。
原文链接:blog.csdn.net/nyist_zxp/article/details/19764607
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)