首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

(DP6.1.4.3)UVA 10534Wavio Sequence(利用2分查找来富足DP)

2013-10-14 
(DP6.1.4.3)UVA 10534Wavio Sequence(利用二分查找来富足DP)/* * UVA_10534.cPP * *Created on: 2013年10

(DP6.1.4.3)UVA 10534Wavio Sequence(利用二分查找来富足DP)

/* * UVA_10534.cPP * *  Created on: 2013年10月13日 *      Author: Administrator */#include <iostream>#include <cstdio>#include <cmath>#include <algorithm>#include <cstring>using namespace std;const int maxn = 10010;int n,A[maxn],L[maxn],F[maxn],G[maxn];int binary( int x){int mid ;int l = 0 ;int r = n;while(l < r){mid =  (l + r)/2;if(L[mid+1] >= x){r = mid;}else{l = mid + 1;}}return l;}int main(){while(scanf("%d",&n)!=EOF){int i;for(i = 1 ; i <= n ; ++i){scanf("%d",&A[i]);}for(i = 1 ; i <= n ; ++i){L[i] = 2147483647;}L[0] = -2147483647 - 1;for(i = 1 ; i <= n ; ++i){F[i] = binary(A[i]) + 1;if(A[i] < L[F[i]]){L[F[i]] = A[i];}}for(i = 1 ; i <= n ; ++i){L[i] = 2147483647;}L[0] = -2147483647 - 1;for(i = n ; i >= 1 ; --i){G[i] = binary(A[i]) + 1;if(A[i] < L[G[i]]){L[G[i]] = A[i];}}int ans = 0;for(i = 1 ; i <= n ; ++i){int k = min(F[i],G[i]);if(ans < k){ans = k;}}printf("%d\n",ans*2-1);//cout<<ans*2-1<<endl;}return 0;}

热点排行