Interceptor missiles
-
Title Description:
-
A missile interception system was 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, radar captures the enemy's missiles and observes the height of the missiles in turn, counting how many missiles the system can intercept. When intercepting incoming missiles, they must be in the chronological order of the incoming missiles, not allowing the rear missiles to be intercepted, and then intercepting the missiles in front of them.
-
Input:
-
Each set of inputs has two lines, the first line, the number of enemy missiles captured by the input radar K (k<=25),
In the second line, enter k positive integers, indicating the height of the K-missiles, given in the order of attack time of the attacking missiles, separated by a space.
-
Output:
-
Each set of outputs has only one row and contains an integer that indicates how many missiles can be intercepted.
-
Sample input:
-
8300 207 155 300 299 170 158 65
-
-
Sample output:
-
6
Code:
#include <cstdio>using namespacestd;intMaxval (intAintb) { returnA>b?a:b;} intMain () {Const intArrsize= -; intArr[arrsize]; intDp[arrsize]; intN; while(SCANF ("%d", &n)! =EOF) { for(intI=1; i<=n;++i) {scanf ("%d",&Arr[i]); Dp[i]=0; } for(intI=1; i<=n;++i) { inttmax=1; for(intj=1; j<i;++j) { if(arr[j]>=Arr[i]) Tmax=maxval (tmax,dp[j]+1); } Dp[i]=Tmax; } intcnt=dp[1]; for(intI=1; i<=n;++i) { if(dp[i]>CNT) CNT=Dp[i]; } printf ("%d\n", CNT); } return 0;} /************************************************************** problem:1112 User:lcyvino language:c++ Re sult:accepted time:0 Ms memory:1020 kb****************************************************************/
maximum sequence and
-
Title Description:
-
Gives an integer sequence s, with n number, that defines the "sequence and" of T in one of the non-empty contiguous subsequence T.
For all non-empty contiguous subsequence t of S, the maximum sequence is obtained.
Variable conditions: N is a positive integer, n≤1000000, the result sequence and within the range ( -2^63,2^63-1).
-
Input:
-
The first behavior is a positive integer n, and the second behaves n integers, representing the number in the sequence.
-
Output:
-
Input may include multiple sets of data, for each set of input data,
Only one number is output, representing the maximum sequence and.
-
Sample input:
-
51 5-3 2 461-2 3 4-10 64-3-1-2-5
-
-
Sample output:
-
97-1
Code:
#include <cstdio>using namespacestd;Const intArrsize=1000010;Long LongArr[arrsize];Long LongDp[arrsize];intMain () {intN; while(SCANF ("%d", &n)! =EOF) { for(intI=1; i<=n;++i) {scanf ("%lld",&Arr[i]); Dp[i]=0; } for(intI=1; i<=n;++i) { Long Longtmax=Arr[i]; if(i>1){ if(dp[i-1]>0) {Dp[i]=dp[i-1]+Arr[i]; Continue; }} Dp[i]=Tmax; } Long Longresult=dp[1]; for(intI=1; i<=n;++i) { if(dp[i]>result) Result=Dp[i]; } printf ("%lld\n", result); } return 0;} /************************************************************** problem:1077 User:lcyvino language:c++ Re sult:accepted time:120 Ms memory:16644 kb****************************************************************/
Chorus formation
-
Title Description:
-
N students stand in a row, the music teacher to please one of the students (N-K) out, so that the rest of the K-students do not exchange position can be lined up in chorus formation.
Chorus formation refers to such a formation: Set K-Students from left to right numbered 1, 2, ..., K, their height, respectively, T1, T2, ..., TK,
Then their height meets T1 < T2 < ... < Ti, ti > Ti+1 > ... > TK (1 <= i <= K).
Your task is to know the height of all n students, calculate the minimum number of students need to dequeue, you can make the rest of the students lined up in chorus formation.
-
Input:
-
The first line of input is an integer n (2 <= n <= 100), representing the total number of classmates.
The first line has n integers, separated by a space, and the I-Integer ti (<= ti <= 230) is the height of the Class I (cm).
-
Output:
-
May include multiple sets of test data, for each set of data,
The output includes a row, which contains only an integer, which requires a minimum of several classmates to dequeue.
-
Sample input:
-
8186 186 150 200 160 130 197 220
-
-
Sample output:
-
4
Code:
#include <cstdio>using namespacestd;intMaxval (intAintb) { returnA>b?a:b;} intMain () {Const intArrsize= the; intArr[arrsize]; intDpup[arrsize]; intDpdown[arrsize]; intN; while(SCANF ("%d", &n)! =EOF) { for(intI=1; i<=n;++i) {scanf ("%d",&Arr[i]); Dpup[i]=0; Dpdown[i]=0; } for(intI=1; i<=n;++i) {//using Lis in positive direction inttmax=1; for(intj=1; j<i;++j) { if(arr[j]<Arr[i]) Tmax=maxval (tmax,dpup[j]+1); } Dpup[i]=Tmax; } for(inti=n;i>=1;-I.) {//reverse use of LIS inttmax=1; for(intj=n;j>i;--j) { if(arr[j]<Arr[i]) Tmax=maxval (tmax,dpdown[j]+1); } Dpdown[i]=Tmax; } intcnt=dpup[1]+dpdown[1]; for(intI=1; i<=n;++i) { if(dpup[i]+dpdown[i]>CNT) CNT=dpup[i]+Dpdown[i]; } printf ("%d\n", N-(cnt-1)); } return 0;} /************************************************************** problem:1131 User:lcyvino language:c++ Re sult:accepted time:740 Ms memory:1020 kb****************************************************************/
About the longest increment subsequence (LIS)