Title Description:
A country has developed a missile interception system in order to defend itself against enemy missile attacks.However, this missile interception system has one drawback: although its first shell can reach any height, each subsequent shell cannot be higher than the previous one.One day, the radar caught the enemy's missile attack.Since the system is still in trial, there is only one system and it is possible that all missiles will not be intercepted.(
Input:
Each test file contains only one set of test data, each set of input integers to represent the altitude of the missile in turn (Radar gives a positive integer of no more than 30,000)
Output:
For each set of input data, the first line outputs the maximum number of missiles that the system can intercept, and the second line outputs the minimum number of such missile intercept systems to intercept all missiles.(
Analysis: The maximum interceptable missile is the longest ascending subsequence, and what the missile system intercepts is actually the longest descending subsequence.
#include<map> #include<set> #include<cmath> #include<queue> #include<stack> #include<cstdio> #include<vector> #include<cctype> #include<cstring> #include<utility> #include<cstdlib> #include<iomanip> #include<iostream> #include<algorithm> #define Clear(x) memset(x,0,sizeof(x)) #define fup(i,a,b) for(int i=a;i<b;i++) #define rfup(i,a,b) for(int i=a;i<=b;i++) #define fdn(i,a,b) for(int i=a;i>b;i--) #define rfdn(i,a,b) for(int i=a;i>=b;i--) typedef long long ll; using namespace std; const int maxn = 1e6+7; const int inf = 0x3f3f3f3f; const double pi=acos(-1.0); const double eps = 1e-8; int n=0,a[maxn]; int dp[maxn]; int main() { while(scanf("%d",&a[n])!=EOF) n++; int ans=-inf; fup(i,0,n) dp[i]=1; fup(i,0,n){ fup(j,0,i){ if(a[j]>a[i]) dp[i]=max(dp[i],dp[j]+1); } ans=max(ans,dp[i]); } printf("%d\n",ans); ans=-inf; fup(i,0,n) dp[i]=1; fup(i,0,n){ fup(j,0,i){ if(a[j]<a[i]) dp[i]=max(dp[i],dp[j]+1); } ans=max(ans,dp[i]); } printf("%d\n",ans); return 0; }