攔截導彈
時間限制:3000 ms | 內存限制:65535 KB
難度:3
- 描述
-
某國爲了防禦敵國的導彈襲擊,發展中一種導彈攔截系統。但是這種導彈攔截系統有一個缺陷:雖然它的第一發炮彈能夠到達任意的高度,但是以後每一發炮彈都不能高於等於前一發的高度。某天,雷達捕捉到敵國導彈來襲。由於該系統還在試用階段,所以只用一套系統,因此有可能不能攔截所有的導彈。
- 輸入
- 第一行輸入測試數據組數N(1<=N<=10)
接下來一行輸入這組測試數據共有多少個導彈m(1<=m<=20)
接下來行輸入導彈依次飛來的高度,所有高度值均是大於0的正整數。 - 輸出
- 輸出最多能攔截的導彈數目
- 樣例輸入
-
2 8 389 207 155 300 299 170 158 65 3 88 34 65
- 樣例輸出
-
6 2
- 來源
- [張潔烽]原創
- 上傳者
import java.io.BufferedInputStream; import java.util.Scanner; public class _79_3_AC最長遞減子序列 { public static void main(String[] args) { int[] lens = null, data = null; Scanner scan = new Scanner(new BufferedInputStream(System.in)); int testData = scan.nextInt(); while (testData-- > 0) { int num = scan.nextInt(); lens = new int[num]; data = new int[num]; for (int i = 0; i < num; ++i) { lens[i] = 1; data[i] = scan.nextInt(); } for (int i = 1; i < data.length; ++i) { for (int j = 0; j < i; ++j) { if (data[j] > data[i] && lens[i] <= lens[j]) { lens[i] = lens[j] + 1; } } } int max = lens[0]; for(int i = 1; i < lens.length; ++i){ if(lens[i] > max){ max = lens[i]; } } System.out.println(max); } } }