DP46--The 21st problem--two algorithms dp/simulation of interception system

Source: Internet
Author: User
Tags acos cmath radar

HDU 1556 Color the ball problem Solving report

First, the original question

Minimum interception systemTime limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 24565 Accepted Submission (s): 9628


Problem description A missile interception system developed by a country to defend against enemy missile attacks. But there is a flaw in this missile interception system: Although its first shells can reach any height, each shot cannot exceed the height of the previous one. Someday, The radar captures the enemy's missiles. Since the system is still in trial, there is only one set of systems that may not 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 enters several sets of data. Each group of data includes: Total number of missiles (positive integers), the height at which missiles fly (radar-given height data is a positive integer not greater than 30000, separated by a space)

Output corresponds to each set of data outputs to intercept all missiles with a minimum of how many sets of such missile interception systems.

Sample Input
8 389 207 155 300 299 170 158 65

Sample Output
2


Second, the Code

1. Simple simulation

/********************************* Date: 2015-06-03 matrix68 question number: HDU 1257-Minimum Interception system Summary: Analog 1: Use a Mhigh array to record all missile interception systems currently The highest height supported each time the search can intercept arr[i] in the missile system Mhigh[i] the lowest one and update his mhigh[i] to Arr[i] The final output mhigh capacity can be Tricks: The topic does not give the capacity, note Italian array open a little **********************************/#include <cstdio> #include <set> #include <iostream># Include <string> #include <vector> #include <queue> #include <cstring> #include <iomanip> #include <algorithm> #include <cctype> #include <string> #include <map> #include <cmath># Define MP (A, B) Make_pair (A, b) #define PB push_back#define lowbit (x) ((x) & (×)) #define REP (i,n) for (int i=0;i<n;i + +) #define MEM (Arr,val) memset (arr), (Val), (sizeof (ARR))) #define LL long longconst double PI = ACOs ( -0); const int MAXN = 10000 + 10;const int MOD = 1000007;const int dir[][2] = {{-1, 0}, {1, 0}, {0,-1}, {0, 1}};using namespace Std;int arr[m Axn];int Mhigh[maxn];int Main () {//Freopen ("in. txt "," R ", stdin);    int n;         while (~SCANF ("%d", &n)) {Rep (i,n) {scanf ("%d", &arr[i]);         } int index=0;         MHIGH[INDEX++]=ARR[0];            for (int i=1;i<n;i++) {int j=0;            int minklj=-1; for (j;j<index;j++) {if (Arr[i]<mhigh[j]) {if (Minklj!=-1&amp                  ; &mhigh[j]<mhigh[minklj]) minklj=j;               else if (minklj==-1) minklj=j;            }} if (Minklj!=-1) mhigh[minklj]=arr[i];         else Mhigh[index++]=arr[i];    } cout<<index<<endl; } return 0;}

2.DP to find the longest strict increment sequence


/********************************* Date: 2015-06-03 matrix68 question number: HDU 1257-Minimum Interception system Summary: DP idea 2: For each system, if you can intercept arr[i], you must          You can no longer intercept the one larger than arr[i]. So here we are directly seeking the longest strictly ascending sequence Tricks: The topic does not give the capacity, note the array opens a little bit **********************************/#include <cstdio> #include < set> #include <iostream> #include <string> #include <vector> #include <queue> #include < cstring> #include <iomanip> #include <algorithm> #include <cctype> #include <string>#  Include <map> #include <cmath> #define MP (A, B) Make_pair (A, b) #define PB push_back#define lowbit (x) ((x) & (-X)) #define REP (I,n) for (int i=0;i<n;i++) #define MEM (Arr,val) memset (arr), (Val), (sizeof (ARR))) #define LL Long Longconst Double PI = ACOs ( -0); const int MAXN = 10000 + 10;const int INF = 99999;const int MOD = 1000007;const int dir[][2 ] = {{-1, 0}, {1, 0}, {0,-1}, {0, 1}};using namespace Std;int arr[maxn];int dp[maxn];int main () {//Freopen ("In.txt",    "R", stdin);    int n; while (~scanf ("%d", &n)) {Rep (i,n) {scanf ("%d", &arr[i]);         Dp[i]=1;         } int ans=-inf;               for (int i=0;i<n;i++) {for (int j=0;j<i;j++) {if (Arr[j]<arr[i])               {Dp[i]=max (dp[j]+1,dp[i]);         }} if (Dp[i]>ans) ans=dp[i];    } cout<<ans<<endl; } return 0;}



DP46--The 21st problem--two algorithms dp/simulation of interception system

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.