Topic link:
https://cn.vjudge.net/problem/POJ-1836
Topic meaning:
The meaning of the question: After the minimum number of soldiers in the original queue is dequeued, any soldier in the new queue can see infinity on the left or right. That is to make the new queues are distributed in a triangular shape.
Problem solving ideas:
Find the longest ascending subsequence ending at each bit and the longest descending subsequence starting at each bit, find the maximum value, and subtract it from the queue length.
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #include<cmath> 6 #include<queue> 7 #include<stack> 8 #include<map> 9 #include<sstream> 10 using namespace std; 11 typedef long long ll; 12 int dp1[1005], dp2[1005]; 13 double a[1005]; 14 int main() 15 { 16 int n; 17 cin >> n; 18 for(int i = 1; i <= n; i++)cin >> a[i], dp1[i] = 1, dp2[i] = 1; 19 for(int i = 1; i <= n; i++) 20 { 21 for(int j = 1; j < i; j++) 22 if(a[i]>a[j])dp1[i] = max(dp1[i], dp1[j] + 1); 23 } 24 for(int i = n; i >= 1; i--) 25 { 26 for(int j = n; j > i; j--) 27 if(a[i]>a[j])dp2[i] = max(dp2[i], dp2[j] + 1); 28 } 29 int ans = 0; 30 for(int i = 1; i <= n; i++) 31 for(int j = i + 1; j <= n; j++) 32 ans = max(dp1[i] + dp2[j], ans); 33 cout<<n - ans<<endl; 34 }