Difficulty: popularity/improvement-
Topic Type: dynamic regulation
Number of submissions: 1
related knowledge: linear motion Regulation
Title Description
A missile interception system has been developed by a country to defend against enemy missile attacks. But the missile interception system has a flaw: although its first artillery shells can reach any height, each projectile cannot be higher than the previous one. One day, the radar caught the enemy's missiles to attack. Since the system is still in the trial phase, there is only one set of systems that may not intercept all missiles.
The height of the input missiles in turn (the radar gives a positive integer not greater than 30000), calculates how many missiles the system can intercept, and how many of these missile interceptors should be equipped to intercept all missiles.
Input/output format
Input format:
One row, several positive integers.
Output format:
2 lines, one integer per line, the first number indicates how many missiles the system can intercept, and the second number indicates how many of these missile interceptors should be equipped to intercept all missiles at least.
Code:
1#include <iostream>2#include <cstdio>3 using namespacestd;4 inta[10005];5 intd[10005];6 intMain () {7 intI, j, n =0;8d[0] =1;9 while(cin>>A[n]) {Tenn++; OneD[n] =1; A } - - for(i =0; I < n; i++) the for(j =0; J < I; J + +) - if(a[i]<A[j]) -D[i] = max (D[i], d[j]+1); - intAns =0; + for(i =0; I < n; i++) -Ans =Max (ans, d[i]); +cout<<ans<<Endl; A at For (i = 0; i < n; i++) d[i] = 1; - ans = 0; - - for(i =0; I < n; i++) - for(j =0; J < I; J + +) - if(a[j]<A[i]) inD[i] = max (D[i], d[j]+1); - for(i =0; I < n; i++) toAns =Max (ans, d[i]); +cout<<ans<<Endl; - return 0; the}
Note:
The second question is difficult. The puzzle says it can be converted to the longest ascending sequence, but I don't know why for a day. See a blogger that explains "... Every missile in this sequence cannot be stopped with the same interception system ... ", which means that each missile has to have a single system, which is well understood. So why is it possible to share a system with one of the missiles in this sequence outside of this sequence? I have made full use of our thinking method in the training of mathematics self-recruit class (...). ) analysed it for a moment. From the reverse side, it can be understood that a number outside of this sequence can always find a sequence larger than it before it or a number smaller than it within the sequence, which is shared with others. From the reverse side, if there is a sequence of missiles outside of it, all the numbers in the previous sequence are smaller than it, and all the numbers in the sequence are larger than it, then it must be within the longest ascending subsequence. Inconsistent with assumptions outside the sequence.
Wow, that's a pretty good proof. Praise yourself, this class is really not white.
However, there are no eggs to use. I can't even think of it from the front.
1020 Missile Intercept