Minimum Interception System
Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 9038 accepted submission (s): 3513
Problem description
A country wants to defend against missile attacks by the enemy , Developed a missile interception system . However, this missile interception system has a defect. : Although its first shell can reach any height , However, in the future, each shell cannot exceed the height of the previous one. . One day , Radar captures missiles from the enemy's country . The system is still in trial , So there is only one system , Therefore, it is possible that all missiles cannot be intercepted. .
What should I do? ? How many more systems are involved? ! It's easy for you to talk about it. , Cost? ? The cost is a big problem. . So I am here for help. , Please help calculate the minimum number of interception systems required .
Input
Enter several groups of data.Each group of data includes:Total number of missiles(Positive Integer),The height of the missile flying here(The height data given by the radar is not greater30000Is a positive integer.,Separated by Spaces)
Output
The minimum number of such missile interception systems required for each set of data output interceptions of all missiles.
Sample Input
8 389 207 155 300 299 170 158 65
Sample output
2
**************************************** **************************************** ***********************************
Question link: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1257
This question is intended to identify the number of substrings that do not increase the sub-sequence, two versionsCodeLength is not long:
In the gentle version: Find a tag and set the number of cycles required. The advantage is that the memory is small and the time is small...
# Include <cstdio> # include <cstring> # define maxn 30100 # define INF 999999int Val [maxn]; // input data int vis [maxn]; // vis judge duplicate table int main () {int N, I, j; while (~ Scanf ("% d", & N) {memset (VIS, 0, sizeof (VIS); for (I = 0; I <n; I ++) scanf ("% d", & Val [I]); int t = n; // T is used to record the number of uncomputed records! Int tot = 0; // Tot is the required number of sets while (t) {tot ++; int maxn = inf; for (I = 0; I <n; I ++) // This loop is used to find non-rising data if (! Vis [I] & Val [I] <maxn) {vis [I] = 1, maxn = Val [I]; t --;}} printf ("% d \ n", TOT);} return 0 ;}
In a brute-force version: Read a data record and it will be recycled multiple times. The time will be too long and the memory will not be able to stand it !!
# Include <cstdio> # include <cstring> # define maxn 10001int an [maxn]; int Val [100] [maxn * 3]; // The Val two-dimensional array 'row' is used to indicate the number of sets. Every time a number is read, there are rows following the first row as much as possible. // but it cannot be greater than the previous one! Int main () {int I, j, N, TOT, X; // How many sets of while (~ Scanf ("% d", & N) {memset (an, 0, sizeof (an); // clear 0 memset (Val, 0, sizeof (VAL )); TOT = 0; for (I = 1; I <= N; I ++) {scanf ("% d", & X); For (j = 0; j <tot; j ++) // read a number, even if it is one if (Val [J] [an [J]> X) {// a row-to-row ratio, if it can be placed in a row, it stops! An [J] ++; Val [J] [an [J] = x; break;} If (j = ToT) {// if it is not appropriate, just open a new row to store, indicating that a set of Val [tot] [an [tot] = x; Tot ++ ;}} printf ("% d \ n ", TOT);} return 0 ;}