Dynamically plan Missile interception and plan Missile interception

Source: Internet
Author: User

Dynamically plan Missile interception and plan Missile interception

A: The first shell of a missile interception system can reach any height, but each shell in the future cannot be higher than the previous one. One day, radar capturing

A missile strikes the enemy's country. Because the system is still in the trial phase, there is only one system, so it may not be able to intercept all missiles. Input the height of missiles flying in sequence

Measure the test taker's knowledge about how many missiles the system can intercept. How many missile interception systems are required to intercept all missiles?

The first question is very simple, constantly changing the position of the termination point and updating the dp array.

# Include <iostream> # include <cstdio> # include <algorithm> # include <cstring> using namespace std; int dp [1010], a [1010]; int main () {int cases; cin> cases; while (cases --) {memset (dp, 0, sizeof (dp); int n; cin> n; for (int I = 0; I <n; I ++) scanf ("% d", & a [I]); dp [0] = 1; // The minimum subsequence must be 1, and no smaller for (int I = 1; I <n; I ++) for (int j = 0; j <I; j ++) if (a [I] <a [j] & dp [j] + 1> dp [I]) {dp [I] = dp [j] + 1 ;}cout <* max_element (dp, dp + n) <endl ;}}

The second question is difficult.

Let's abstract the question of the second question, that is: divide a series into the longest ascending subsequence with the least number.

Dilworth Theorem

# Include <iostream> # include <cstdio> # include <algorithm> # include <cstring> using namespace std; int dp [1010], a [1010]; int main () {int cases; cin> cases; while (cases --) {int n; cin> n; fill (dp, dp + n, 1 ); for (int I = 0; I <n; I ++) scanf ("% d", & a [I]); dp [0] = 1; // The minimum subsequence must be 1, and no smaller for (int I = 1; I <n; I ++) for (int j = 0; j <I; j ++) if (a [j] <a [I] & dp [j] + 1> dp [I]) {dp [I] = dp [j] + 1 ;}// changes; cout <* max_element (dp, dp + n) <endl ;}}

The idea is to record them from the beginning to the tail, so you can stick them together.

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.