HDU 1257--minimum interception system —————— "LIS variant Problem"

Source: Internet
Author: User
Tags radar

Minimum interception systemTime limit:1000MS Memory Limit:32768KB 64bit IO Format:%i64d &%i64 U SubmitStatusPracticeHDU 1257

Description

A missile interception system has been developed by a country to defend against enemy missile attacks. But there is a flaw in the missile interception system: Although its first artillery shells can reach any height, each shot cannot exceed the height of the previous pitch. One day, the radar caught the enemy's missiles. As the system is still in the trial phase, So there is only one set of systems, so it is possible not to intercept all missiles.
What do we do? How many systems do you have? It's easy to say it. Cost is a big problem. So I came here to call for help, please figure out how many sets of interception systems you need at least.

Input

Enter several sets of data. Each group of data includes: Total number of missiles (positive integers), the height at which the missiles are flown (radar-given height data is a positive integer not greater than 30000, separated by a space)

Output

corresponding to each set of data output intercept all missiles with a minimum of how many sets of this missile interception system.

Sample Input

8 389 207 155 300 299 170 158 65

Sample Output

2 Problem-solving ideas: Define Dp[i] Indicates the minimum number of interception systems required to be able to knock out the first missile. is actually an application of LIS. Dp[i] = max (dp[i],dp[j]+1), j:1<= J < I. In the LIS, Dp[i] defines the longest increment subsequence length that represents the end of the first element.
#include <bits/stdc++.h>using namespace Std;const int maxn = 1e5;int A[maxn],dp[maxn];int main () {    int n;    while (scanf ("%d", &n)!=eof) {for        (int i = 1; I <= n; i++) {            scanf ("%d", &a[i]);            Dp[i] = 1;        }        for (int i = 1, i <= N; i++) {for            (int j = 1; j < I; J + +) {                if (A[j] <= a[i]) {                    dp[i] = max (Dp[i],dp[j] +1 );                }            }        }        int ans = 0;        for (int i = 1; I <= n; i++) {            //printf ("%d", Dp[i]);            ans = max (ans,dp[i]);        }        printf ("%d\n", ans);    }    return 0;}

  

HDU 1257--minimum interception system —————— "LIS variant Problem"

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.