Team-based (Dynamic Planning)

Source: Internet
Author: User
Descriptionn 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,… from left to right ,..., K. Their heights are T1, T2 ,..., TK, then their height is equal to t1 <t2 <... <Ti, Ti> 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.



The first line of input 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 includes a row. This row contains only one integer, that is, at least a few columns are required.


Sample input8
186 186 150 200 160 130 197


Sample output4 Solution:Select a student in the queue and take the student as the core. Find the longest ascending subsequence on the left and the longest descending subsequence on the right, respectively, the sum of the two minus 1 is the number of the student-centered teams. Therefore, we only need to traverse each student as the center to obtain the largest number of student teams, the total number minus the chorus number is the number of people to be removed. AC code:
# Include <iostream> # include <cstdio> # define max_num 105 using namespace STD; int main () {int high [max_num], left [max_num], right [max_num], n; scanf ("% d", & N); For (INT I = 0; I <n; I ++) scanf ("% d ", & high [I]); For (INT I = 0; I <n; I ++) {left [I] = 1; for (Int J = 0; j <I; j ++) {If (high [J] 


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.