标签:sed pst his stdio.h mos too accept nbsp body
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 14486 | Accepted: 4695 |
Description
Input
Output
Sample Input
8 1.86 1.86 1.30621 2 1.4 1 1.97 2.2
Sample Output
4
Source
#include<iostream> #include<algorithm> #include<stdio.h> #include<string.h> #include<stdlib.h> #define inf 9999 #define INF -9999 using namespace std; int n; double a[1010]; double dp1[1010],dp2[1010]; int res1(int len,double num) { int l = 0; int r = len; while(l!=r) { int mid = (l + r) >> 1; if(dp1[mid] == num) { return mid; } else if(dp1[mid]<num) { l = mid + 1; } else { r = mid; } } return l; } int res2(int len,double num) { int l = 0; int r = len; while(l!=r) { int mid = (l+r)>>1; if(dp2[mid] == num) { return mid; } else if(dp2[mid]>num) { l = mid + 1; } else { r = mid; } } return l; } int main() { while(scanf("%d",&n)!=EOF) { for(int i=1; i<=n; i++) { scanf("%lf",&a[i]); } int len1 = 1,len2 = 1; dp1[0] = -99; dp2[0] = 99; int maxx = -100; for(int i=1; i<n; i++) { int ans = 0; len1 = 1; dp1[0] = -99; for(int j=1; j<=i; j++) { dp1[i] = inf; int k1 = res1(len1,a[j]); if(k1 == len1) { len1++; } dp1[k1] = a[j]; } ans = len1 - 1; len2 = 1; dp2[0] = 99; for(int j=i+1; j<=n; j++) { int t = (j - i); dp2[t] = INF; int k2 = res2(len2,a[j]); if(k2 == len2) { len2++; } dp2[k2] = a[j]; } ans += len2 - 1; maxx = max(maxx,ans); } printf("%d\n",n - maxx); } return 0; }
POJ 1836 Alignment(DP max(最长上升子序列 + 最长下降子序列))
标签:sed pst his stdio.h mos too accept nbsp body
原文地址:http://www.cnblogs.com/llguanli/p/6979737.html