HDU1257 _ minimal interception system (LIS]

Source: Internet
Author: User
Minimum interception system

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission (s): 19460 Accepted Submission (s): 7735
Problem Description
A country develops a missile interception system to defend against missile attacks by the enemy. however, this missile interception system has a defect: although its first shell can reach any height, it cannot exceed the height of the previous one. one day, the radar captured the enemy's missiles. because the system is still in the trial phase, there is only one system, so it may not be able to intercept all missiles.
What should we do? How many more systems are involved! It's easy to talk about. What about the cost? The cost is a big problem, so I am here for help. Please help calculate the minimum number of interception systems required.
 
Input
Enter several groups of data. Each set of data includes the total number of missiles (positive integers), and the height of missiles flying here (the height data given by the radar is a positive integer not greater than 30000, separated by spaces)
 
Output
The minimum number of such missile interception systems required for each set of data output to intercept all missiles.
 
Sample Input
8 389 207 155 300 299 170 158 65
 
Sample Output
2
 
Source

The fourth college program design competition of Zhejiang University of Technology


The height of each missile intercepted by the missile interception system is no higher than that of the previous missile interception system.

I will give you a sequence of missile launching heights. How many interception systems can be used to complete interception?

Idea: Many people say it is the longest ascending subsequence (not descending. But it is hard to understand. So

Why is it the longest ascending subsequence.

This is because, assuming the length of the longest ascending subsequence is N, each element of the longest ascending subsequence is

The elements of the non-longest ascending subsequence on the right must fall. It must be the best case. Set

The element of the long ascending subsequence acts as the starting point of an interception system, and its right side is smaller than its own

The sequence is the missile that the interception system can intercept, before the element of the next longest ascending subsequence.

The element of a non-longest ascending subsequence is the end point. The length of the longest ascending subsequence can be covered.

If all descending sequences are dropped, the maximum length of the ascending subsequence is the minimum number of intercepted systems.


# Include <stdio. h> # include <string. h> int arr [30010], lis [30010]; int list (int arr [], int n) // arr [] stores the array to be evaluated {int I, j, max; // max indicates the maximum length of the ascending subsequence. max = 0; for (I = 1; I <= n; I ++) lis [I] = 1; // lis [I] specifies the length of the largest ascending subsequence before storing I. Initially, it is 1 for (I = 2; I <= n; I ++) {for (j = 1; j <I; j ++) // traverse all locations before I {if (arr [I]> = arr [j] & lis [I] <lis [j] + 1) // arr [I]> arr [j] is an incremental lis [I] <lis [j] + 1. Ensure that the current longest incremental sequence lis [I] = lis [j] + 1 ;}} for (I = 1; I <= n; I ++) if (max <lis [I ]) Max = lis [I]; return max;} int main () {int n, I, max; while (~ Scanf ("% d", & n) {for (I = 1; I <= n; I ++) scanf ("% d ", & amp; arr [I]); max = list (arr, n); printf ("% d \ n", max);} return 0 ;}





HDU1257 _ minimal interception system (LIS]

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.