Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
很屌的数据。。。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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator