Title DescriptionDescription
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.
Enter a descriptionInput Description
The height of the input missile in turn (the height data given by the radar is a positive integer not greater than 30000)
Output descriptionOutput Description
Output the maximum number of missiles the system can intercept, and the minimum number of such missile interceptors to be equipped to intercept all missiles.
Sample inputSample Input
389 207 155 300 299 170 158 65
Sample outputSample Output
6
2
Data range and TipsData Size & Hint
Missile height <=30000, missile number <=20
The first time I saw the output required a few sets of interception system is really ignorant. Half an hour to think no fruit, go to the canteen to eat bowl noodles back on the road suddenly epiphany, a few sets of equipment is not a longest ascending sub-sequence problem, as long as the height of the rise, the previous interception state will not be able to successfully intercept, want to understand, the code is very good to write, not in-depth consideration, Now just paste the code for the longest descending sub-sequence to change the size of the symbol, it seems a bit of a violent taste, but fortunately it was an AC,
At the same time, the number of input number is not pre-given, you need to write code to determine whether the input is complete, ask wwx great God after really long knowledge ah!
int num = 0;
This brutal writing incredibly will solve the problem, again worship Orz (Vulgar head big). Do not optimize the code will be thrown out!
#include <cstdio> #include <iostream> #include <algorithm> #include <memory.h> #include < cstring> #include <cmath> #include <ctype.h> #include <stack> #include <queue> #include < vector> #include <list> #include <set>using namespace Std;int a[100],b[100];//int n=0;int main () {//scanf ("%d", &n);//for (int i=0;i<n;i++)//scanf ("%d", &a[i]); int num = 0; while (~SCANF ("%d", &a[num++]) {} for (int i=0;i<100;i++) b[i]=1; int max1=1; int Max; for (int i=0;i<num;i++) {max=0; for (int j=0;j<i;j++) {if (A[j]>a[i] && B[j]>max) max=b[j]; } b[i]=max+1; if (B[I]>MAX1) max1=b[i]; } printf ("%d\n", max1-1); Max1=1; for (int i=0;i<100;i++) b[i]=1; for (int i=0;i<num;i++) {max=0; for (int j=0;j<i;j++) {if (A[j]<a[i] && b[J]>max) max=b[j]; } b[i]=max+1; if (B[I]>MAX1) max1=b[i]; } printf ("%d\n", Max1);}
used two times the output, after the first output continues to run, the loss of data is small, if the big must time out,,, to be optimized.
Missile intercept (longest descent sub-sequence) variant