Timeline (one-dimensional linear dp recurrence)
DescriptionDescriptionN students stood in a row, and the music teacher asked the (N-K) students to make the remaining K students lined up.
A queue is a formation in which K students are numbered 1, 2, and so on from left to right ..., K. Their heights are T1, T2 ,..., TK, then their height meets T1 <... Ti + 1>...> TK (1 <= I <= K ).
Your task is to know the height of all N students. The calculation requires at least a few students to make the remaining students form a queue.
Input Format:
The first line of the input file chorus. in is an integer N (2 <= N <= 100), indicating the total number of students. The first line contains n integers separated by spaces. the I-th integer Ti (130 <= Ti <= 230) is the height (cm) of the I-th student ).
Output Format:
The output file chorus. out contains a row. This row contains only one integer, that is, at least a few students are required to columns.
8
186 186 150 200 160 130 197
4
#include
#include
#include
#include
using namespace std;int que[110];int dp_u[110];int dp_d[110];int main(){ int n; while(scanf("%d",&n)!=EOF) { for(int i=0;i
mu&&que[i]>que[j]) mu=dp_u[j]; } dp_u[i]=mu+1; } for(int i=n-2;i>=0;i--){ int md=0; for(int j=n-1;j>i;j--){ if(dp_d[j]>md&&que[i]>que[j]) md=dp_d[j]; } dp_d[i]=md+1; } int res=10000; for(int i=0;i