Test instructions
The minimum number of interception systems is required to intercept all missiles.
Ideas:
The 1th missile must have the first interception system, and the 2nd missile would require a second interception system if it was higher than the 1th height.
Consider the I missile, if the former I-1 missile height is smaller than it, then need a new interception system, or must only one of the previous interception system, do not need to open a new interception system.
The reason: Assuming that the optimal scheme is for it to open a new interception system, then must be all the previous interception system to intercept some of the missiles behind it, so skip it.
And we could have a previous interception system to intercept it, and the new interception system would intercept the missile behind it.
So it proves that there is no need to open a new interception system, as long as it is higher than the missile.
So which interception system should we have to intercept it? Find all interception systems that can intercept it and the height of the last intercept is the small one. This is optimal.
Open an array to record the height of the missile that was last intercepted by each interception system under the optimal scheme.
Look at the code.
Code:
intN;inth[100005];intd[100005];intMain () { while(SCANF ("%d", &n)! =EOF) {Rep (i,1, N) scanf ("%d",&H[i]); d[1]=h[1]; intNc=1; Rep (I,2, N) { if(h[i]>D[NC]) {d[++nc]=H[i]; }Else{ intPos=lower_bound (d+1, d+1+nc,h[i])-D; D[pos]=H[i]; }} printf ("%d\n", NC); } return 0;}
HDU 1257 minimum interception system (greedy)