Remove as few numbers as possible from the number of columns so that you can see from left to right. These numbers are from small to large and then from large to small. The number of columns is from small to large.
Problem: the number of columns is filtered out as few as possible so that we can see from left to right. These numbers are from small to large and then from large to small (Netease ).
Solution:This is a dual-end LIS problem. It can be solved using the DP idea. The objective planning function max {B [I] + c [I]}, where B [I] is left to right, 0 ~ The number of I numbers must increase progressively. c [I] is from right to left, n-1 ~ The number of I numbers must increase progressively. The final result is n-max + 1. In DP, an inc [] array can be maintained to represent an ascending number sequence. inc [I] is a number from small to large (this sentence can be understood as follows, inc [I] indicates the minimum end number of an ascending sequence when its length is I. For more information, see the above analysis on the longest descending subsequence ), then, when calculating B [I] c [I], use the binary search to locate the interval inc [0] ~ in inc []. Inc [I-1] is smaller than the number of elements in a [I] (low ).
Suppose it is an array arr [n], and its segment point is I (0-i increments, I to n-1 decreases). Suppose we use the method LIS (I) find the longest ascending subsequence from 0 to I, and find the longest descending subsequence from I to n-1, then its total length is LIS (I) + LDS (I)-1, so we can scan the entire array, that is, let I go from 0 to n-1, and find the largest LIS (I) + LDS (I)-1.
(Before writing the code: let's leave this specific question for the moment. If we simply want to find the longest incrementing subsequence or the longest incrementing subsequence, the method used has been introduced in the previous article, an auxiliary array is used. This auxiliary array table [I] records the longest ascending/descending sequence in the sub-sequence consisting of src [I, this is equivalent to B [I] and c [I], but an auxiliary array inc [I] is added here, which reduces the event complexity, where inc [I] (assuming that inc starts from 1) is the smallest end number in the ascending/descending sequence with the length of I, which is also a typical case of exchanging space for events)
The source code is as follows:
[Cpp]View plaincopy
- /**
- * The problem:
- * Remove as few numbers as possible from the number of columns so that you can see from left to right. These numbers are from small to large and then from large to small (Netease ).
- * Use binary search, perhaps you shoshould compile it with-std = c99
- * Fairywell 2011.
- */
- # Include <stdio. h>
- # Define MAX_NUM (1U <31)
- Int
- Main ()
- {
- Int I, n, low, high, mid, max;
- Printf ("Input how many numbers there are :");
- Scanf ("% d/n", & n );
- /* A [] holds the numbers, B [I] holds the number of increasing numbers
- * From a [0] to a [I], c [I] holds the number of increasing numbers
- * From a [n-1] to a [I]
- * Inc [] holds the increasing numbers
- * VLA needs c99 features, compile with-stc = c99
- */
- Double a [n], B [n], c [n], inc [n];
- Printf ("Please input the numbers:/n ");
- For (I = 0; I <n; ++ I) scanf ("% lf", & a [I]);
- // Update array B from left to right
- For (I = 0; I <n; ++ I) inc [I] = (unsigned) MAX_NUM;
- // B [0] = 0;
- For (I = 0; I <n; ++ I ){
- Low = 0; high = I;
- While (low
- Mid = low + (high-low) * 0.5;
- If (inc [mid] <a [I]) low = mid + 1;
- Else high = mid;
- }
- B [I] = low + 1;
- Inc [low] = a [I];
- }
- // Update array c from right to left
- For (I = 0; I <n; ++ I) inc [I] = (unsigned) MAX_NUM;
- // C [0] = 0;
- For (I = n-1; I> = 0; -- I ){
- Low = 0; high = I;
- While (low
- Mid = low + (high-low) * 0.5;
- If (inc [mid] <a [I]) low = mid + 1;
- Else high = mid;
- }
- C [I] = low + 1;
- Inc [low] = a [I];
- }
- Max = 0;
- For (I = 0; I <n; ++ I)
- If (B [I] + c [I]> max) max = B [I] + c [I];
- Printf ("% d number (s) shocould be erased at least./n", n + 1-max );
- Return 0;
- }
Write down the natural number from small to large, and get a column number '100 ......, The 1,001st digits from left to right are ()
Is 7. Explanation: there are 9 digits in one digit, ranging from 1 to 9; two digits: 10 to 9 ~ 99, a total of 90, that is, 180 digits; 1,001st digits must be one of the three digits. 1001-9-180 = 812,812 then 3 = 270 + 2, so it is 100 + 270-1 = 369, the Middle Number of the next number, that is, 370. That is, number 7
One column is arranged in ascending order. Starting from the first number, the first number is the second of the last number.
Set the first number to a1, and the second number to 2a1. The third number is 4a1 ......
At this time, the rule shows the n-1 power * a1 OF an = 2.
So the power of 32 = 2 is 5-1 * a1, and a1 = 2 can be obtained.
So the tenth Number of a10 = 2's 10-1 Power * 2 result is 1024