Title Algorithm Design Method Choosing Blog of Yuguanglou
First, the iterative method iterative method is a common algorithm design method for the approximate root of equation or equation. The equation is f (x) = 0, exported equivalent form x = g (x) with some mathematical method, and then performs following steps:
(1) The approximate root of an equation is selected, and the variable X0 is assigned to the variable X0; (2) Save the value of the X0 in the variable x1, then calculate the g (x1), and exist of the result to the variable X0; (3) When X0 and X1 The absolute value of the difference is less than the specified accuracy requirements, the calculation of step (2) is repeated. If the equation is rooted, and the approximate root sequence calculated by the above method is converged, the X0 obtained by the above method is considered to be the root of the equation. The above algorithm is expressed as: [algorithm] 法 法 方 方 方 根;;;;; 近 近 近;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; * /} While (FABS (X0-X1)> EPSILON; Printf ("Approximate Roots of Equations is% F / N", X0);} Iterative algorithm is also used to seek the root of the square group, order x = (X0, X1, ..., XN-1) The equation group is: xi = GI (X) (i = 0, 1, ..., n-1), the iterative algorithm for the equation group can be described as follows: [Algorithm] iterative method Root {FOR (i = 0; i Second, exhaustive search method is exhausted to search for a number of candidate solutions that may be solving, in some order, and find out the solutions that meet the requirements of candidate as a problem. [Problem] The six variables of A, B, C, D, E, and F are arranged in the triangle shown in the figure, and the six variables take the integer of [1, 6], and are different. The sum of the sum of the variables on the three sides of the triangle. The figure is a solution. The program introduces variables A, B, C, D, E, F, and allows them to sequentially take 1 to 6 certificates, and test the triangular three sides of the figure shown in the figure thereof in the same conditions, respectively. Whether the sum of the variables is equal, such as equal, as an arrangement that meets the requirements, and outputs them. When these variables take all combinations, the program can obtain all possible solutions. See the procedure below for details. [Program 1] # include In the case where the previous numbers 1, 2, 5 is fixed, the arrangement corresponding to the minimum integer should be selected, and the order of the number of numbers in the back is reversed, such as the order of the numbers 6, 4, and 3., Arrangements 1, 2, 5, 3, 4, 6 are obtained, which is the next arrangement of 1, 2, 4, 6, 5, and 3. The procedures written by the above ideas are as follows. [Program 2] # include The weight and value of N items are stored in array W [] and V [], respectively, and the weight is required to be TW. Consider an N tone group (X0, X1, ..., XN-1), where xi = 0 means that the i-th item is not selected, and Xi = 1 represents the i-th item being selected. Obviously this N-tu group is equivalent to one option. Use enumeration method to solve the backpack problem, you need to enumerate all selected schemes, and according to the above method, we can get a problem solution as long as we enumerate all N tumers. Obviously, the number of n metages having an upper value of 0 or 1 is 2N. Each N tone group actually corresponds to a binary number of length N, and the value of these binary numbers ranges from 0 to 2 N-1. Therefore, if 0 to 2 N-1 is converted to the corresponding binary number, the 2N N tumes we need can be obtained. [Algorithm] MAXV = 0; for (i = 0; I <2N; i ) {b [0..n-1] = 0; convert i into binary numbers, stored in array B; TEMP_W = 0; TEMP_V = 0; for (j = 0; j Third, the proposal process is a method for the problem of the problem of the problem of the problem itself using the problem itself. The solution to the requirements of the problem is N. When n = 1, the solution is or known, or can be easily understood. It is important to use the problem with the problem of the scheduling method, that is, when the problem is obtained from the problem of I-1, the proportion of the problem is 1, 2, ..., A series of solutions of I-1, constructing the problem of problem size is I. Thus, the program can be proced from I = 0 or i = 1, repeatedly, by the solution known to the I-1 size, to obtain a solution of the scale I, until the size N is obtained. Solution. [Problem] Section Calculation Problem Description: Write a program, a given N (N ≦ 100), calculated and output K! (K = 1, 2, ..., n) all effective numbers. Since the required integers may greatly exceed the number of digits of the general integer, the program is stored in a one-dimensional array to store the length of each element of the long integer array to store one digit of the long integer. If there is a M positioned an integer n array a [] storage: n = a [m] × 10m-1 a [m-1] × 10M-2 ... a [2] × 101 a [1] × 100 and use a [0] to store the number M of the long integer N, ie a [0] = m. According to the above conventions, each element of the array stores K! One digit and the second element of the array from the low to the high position, the third element .... For example, 5! = 120, the storage form in the array is: 3 0 2 1 ... The first element 3 indicates a three-digit number of length integers, and then the low to the high position is 0, 2, 1, indicated as an integer 120. Calculate the K! Can be used for prep serialization (k-1)! After continuously adding K-1, it was obtained. For example, known 4! = 24, calculate 5! The original 24 is accumulated 4 times 24 24. See the following procedures. # include [Question] Write the Nth function FIB (N) of the Fibonacci number column. The number of Civic of Fibo is listed as: 0, 1, 1, 2, 3, ..., ie: FIB (0) = 0; FIB (1) = 1; FIB (N) = FIB (N-1) FIB ( N-2) (when n> 1). Write a recursive function: int FIB (INT N) {if (n == 0) Return 0; if (n == 1) Return 1; if (n> 1) Return FIB (N-1) FIB (N- 2);} The execution process of the recursive algorithm is pushed and regained two stages. In the period of the push, the solicity of more complex problems (N) is pushed into a simple problem (scale smaller than N) than the original problem. For example, in the above example, the FIB (N) is solved, and it is pushed to solve FIB (N-1) and FIB (N-2). That is to say, in order to calculate the FIB (N), FIB (N-1) and FIB (N-2) must be calculated, and FIB (N-1) and FIB (N-2) must be calculated, and the FIB must be calculated first. N-3) and FIB (N-4). Up to the subkey until FIB (1) and FIB (0) can be calculated, the results 1 and 0 can be obtained immediately. In the period of progress, there must be a case where it is returned. For example, in the function FIB, when n is 1 and 0. In the regression phase, when the simplest case is obtained, the step by step is returned, and the solution to a slightly complex problem is obtained. For example, after obtaining FIB (1) and FIB (0), the result of the Fib (2) is returned, ..., After obtaining the results of FIB (N-1) and FIB (N-2), the result of obtaining FIB (N) is returned. When writing a recursive function, local variables and parameter knowledge in the function are limited to the current call layer, and when the recursive enters the "simple problem" layer, the parameters and local variables at the original hierarchy are concealed. In a series of "simple questions" layers, they have their own parameters and local variables. Since recursive causes a series of function calls, and there may be a series of repetitive calculations, the recursive algorithm is relatively low. When a hand-altered algorithm can be easily converted into a handling algorithm, the program is usually written according to the recursive algorithm. For example, in the case, the function FIB (N) of the Nth item of the Fiboacci number should be used, that is, the first two items from the Fibo-Cilia number will be calculated from the first two items. Until Calculate the Nth item required. [Problem] Combination Problem Description: Find all the combinations of R number from Nature 1, 2, ..., N. For example, all combinations of n = 5, r = 3 are: (1) 5, 4, 3 (2) 5, 4, 2 (3) 5, 4, 1 (4) 5, 3, 2 (5) 5, 3, 1 (6) 5, 2, 1 (7) 4, 3, 2 (8) 4, 3, 1 (9) 4, 2, 1 (10) 3, 2, 1 analysis list 10 combinations You can use such recursive ideas to consider the algorithm for combined functions. The set function is Void COMB (INT M, INT K) to find all the combinations of K numbers from natural numbers 1, 2, ..., m. When the combined first digital is selected, the subsequent numbers are a combination of K-1 number from the remaining M-1 number. This will change the combination of K-1 number in the M-1 number of combinations of k-1. The function introduced into the combination of work arrays a [], and the first number of the determined K digital combination is placed in a [K], and will be A [] after a combination is obtained. One combination output in the middle. The first number can be M, M-1, ..., K, and function will determine the first number of combinations, there are two possible options, due to the remaining elements that have not been set, continue to recurrent Determine; or because all elements of the combination have been determined, this combination is output. Details see the function COMB in the following procedure. [Program] # include The weight of the N pieces is W0, W1, ..., Wn-1, respectively, and the value of the items are V0, V1, ..., VN-1, respectively. Use recursive search options. Set up a variety of options in front, and retains the total value of the total value to array Option [], the total value of the scheme is stored in the variable Maxv. The new program is currently being investigated, and its item selection is preserved in the array of COP []. It is assumed that the current program has considered the first I-1 item, and now you have to consider the first item; the weight of the item already included is TW; here, if the remaining items are selected, this program can be achieved. The expected value of the total value is TV. The algorithm introduces TV is when the expected value of the total value of the current program is less than the total value Maxv of the previous scheme, continue to investigate the current plan to become meaningless work, and should terminate the current program and immediately check the next scheme. Because when the total value of the program is not larger than the maxv, the program will not be re-examined, while ensuring that the scheme found after the function will be better than the previous program. There are two possibilities for the choice of the first item: (1) Consider the item i is selected, this possibility is only possible when it contains it not exceeding the total weight limit of the scheme. After selecting, continue to recursively consider the choice of the remaining items. (2) Considering the item I is not selected, this possibility is only the case where the value of the value is not included. The recursive algorithm is written as follows: try (item i, the currently selected weight and the total value of the total value of this program may be achieved) {/ * Consider the possibility of item i in the current program * / if (included Item I is acceptable) {contains item I in the current scheme; if (i Writing functions and procedures as follows: [Program] # 程序 DE Consider the procedure of non-recurrent. In order to improve the rate of finding, the program is not simply generating all candidates one by one, but the impact of each item on the candidate will form a candidate solution worth further consideration, and a candidate is through sequential to the formation of each article. There are several situations in the examination of item I: When the item is contained in the total weight of the candidate, the item is included in the candidate solution should continue to consider; in turn, the item should not include In the candidate that is currently being formed. Similarly, only the item is not included in the candidate, or it is possible to find a better candidate than the current temporary optimal solution, it is not included in the candidate; contrary, the item does not include The scheme in the current candidate should not continue to consider. For any solution worth continuing, the program will further consider the next item. [Program] # include } Void main () {DOUBLE MAXV; Printf ("Number of inputs / N"); scanf ("% D", & n); Printf ("Input Limit Weight / N"); scanf ("% 1f", & limitw); Printf ("Enter the weight and value of each article / N"); for (k = 0; k We found that for many problems, the given constraints D is complete, namely I tone group (x1, x2, ..., xi) satisfying only X1, X2, ..., Xi all constraints means J (J j. Therefore, for the constraint set D has a complete problem P, once the determination of a J-group (X1, X2, ..., XJ) violates only X1, X2, ..., XJ, can be affirmed, Any N toll group (x1, x2, xj) (x1, x2, ..., xj, xj 1, x2, xn) prefixed in (x1, x2, ..., x1) is not a problem P, so you don't have to search them. Test them. Backtracking Method is a higher algorithm that is more efficient than the enumeration method using the above nature of these problems. The backtracking method first expresses the state space E of the N-tuple of the problem P to a highly N-position-right ordered tree T, and all the solutions to the problem P in E are all pending solutions to the problem P in T. Tree T is similar to retrieving trees, which can be constructed: The elements in Si can be arranged to XI (1), xi (2), ..., xi (mi-1), | Si | = Mi, I = 1, 2, ..., n. From the root start, every node of the i-layer of T has Mi son. This MI son to their parents, according to the order from left to right, respectively, respectively, Xi 1 (1), XI 1 (2), ..., xi 1 (mi), i = 0, 1 , 2, ..., n-1. According to this configuration, an N-group group (x1, x2, ..., xn) corresponds to a leaf node in T, the root of the root of the T in the path of the leaf node. X1, X2, ..., XN, and vice versa. Further, a prefix I tone group (x1, x2, x2, x1) (x1, x2, ..., xi) corresponds to one non-leaf in T in any 0 ≤ i ≤ N-1, E. Node, the root of T to this path of this non-leaven node, the weights of the I strips are X1, X2, ..., Xi, and vice versa. In particular, any of the n metaps in E is an air prefixed (), corresponding to the root of T. Thus, a solution to the problem P in e Searching a leaf node in T, requiring the n-strip from the n-strip from the root of the root of the Leaves to the n-string N rights x1, X2 , ..., XN satisfies all constraints of constraint set D. Searching in t in t, a natural way is from the root starting, with a depth priority strategy, in turn, sequentially sequentially sequentially meets the prefix (X1i) of constraint conditions (X1i), and the prefix 2 yuan group ( X1, x2), ..., prefix I tuple (x1, x2, ..., xi), ... until i = n so. In the backtracking method, the introduced tree referred to as a state space tree of problem P; an arbitrary node on the tree t is called the state node of the problem P; any of the leaf nodes on the tree T are called a problem P One solution state node; any of the remaining constraints that satisfy the constraint set D is referred to as a question P, which corresponds to a solution P. [Problem] Combination Problem Description: Find all the combinations of R number from Nature 1, 2, ..., N. For example n = 5, R = 3 is all combinations: (1) 1, 2, 3 (2) 1, 2, 4 (3) 1, 2, 5 (4) 1, 3, 4 (5) 1, 3,5 (6) 1, 4, 5 (7) 2, 3, 4 (8) 2, 3, 5 (9) 2, 4, 5 (10) 3, 4, 5, the state space of this problem is : E = {(x1, x2, x3) | xi∈S, i = 1, 2, 3} where: s = {1, 2, 3, 4, 5} constraints are: x1 During the search process, as long as the active state node satisfies the end condition, then it is an answer node and should output it or save it. Since the problem is generally required, the problem is generally required, so after getting an answer node, it is also necessary to get the problem of other solutions until the root of the T is, all son nodes It has been searched. For example, in a combination problem, the root depth from the root depth is prioritized. When traversing to nodes (1, 2), although it meets constraints, it is not an answer node, then we should continue to traverse; when traversing the leaf node (1, 2, 5), because it is already An answer node, saves (or output) the node and retracts to its dual-processes, continue to traverse it; when traversed to nodes (1, 5), because it is already a leaf node, but not satisfied The constraints are also retractable. 3. General processes and technologies of trailing laws are generally built on the process of retrospective solutions, while traversing the tree. In the backtracking method, we generally use non-recursive methods. Next, we give the general process of backtracking the non-creation algorithm: Due to the problem of retrospective, that is, in the process of traverse the status space tree, if you use a non-recursive method, we generally use the stack data structure. At this time, not only can the nodes of the tree that are traversed by the stack, but also conveniently represent the establishment of a child node and backtracking process. For example, in a combination problem, we use a one-dimensional array stack [] indicating the stack. When the stack is started, the root node of the tree. If the element 1 is in the stack, then it is established and traversed (1) node; then if the element 2 is in the stack, it means establishing and traversing (1, 2) nodes; the element 3 is further in the stack, then it is established and traversed ( 1, 2, 3) Node. At this time, it can be judged that it satisfies all constraints, which is a solution, output (or saved). At this time, the top element (3) is out of the stack, that is, the backpoint (1, 2, 3) is back to the node (1, 2). [Problem] Combination Problem Description: Find all combinations from Nature 1, 2, ..., N. The solution to the problem is used to find a problem, and the combination of the found will be stored in A [0], A [1], ..., A [R-1] from a small to large sequence, the combined element satisfies the following properties: (1) a [i 1]> a [i], the latter number is larger than the previous; (2) a [i] -i <= N-R 1. According to the retrospective thinking, find the process can be described below: First give up the number of combinations of several numbers, the candidate combination begins with only one number 1. Because the candidate is satisfied with all the conditions other than the problem scale, the scale is expanded, and it satisfies the above conditions (1), and the candidate combination is changed to 1, 2. Continue this process to obtain a candidate combination 1, 2, 3. The candidate is satisfied with all the conditions including the problem scale, and is therefore a solution. On the basis of this solution, select a candidate, due to the 3 adjustment of 4 on A [2], and adjust all the requirements for problems in the future, get solutions 1, 2, 4 and 1, 2, 5 . Since the 5 cannot be adjusted again, it is to be traced from a [2] to a [1]. At this time, A [1] = 2 can be adjusted to 3, and the forward is protected forward, and the solution 1, 3, 4 is obtained. Repeat the above forward test and backward tracery until you want to retrore from A [0], explain all the solutions that have been finished. The procedures are written as follows: [Program] # define maxn 100 int a [max "; Void Comb (int M, int R) {INT I, J; i = 0; A [i] = 1; do {IF (a [i] -i < = M-R 1 {IF (i == r-1) {for (j = 0; j In order to find a 9 digits that meet the requirements, it has not been filled in a number of beginnings, in a certain order (such as a small to large order), fill in an integer each time, then check the currently filled Can you meet the requirements. In the case of satisfying the requirements, the same method is continued to fill the integer as the next one. If the most recently filled integer does not meet the requirements, change the integer of the filled. If an integer for the current square test is unable to meet the requirements, you have to go back to the previous square, and adjust the integer filled in the previous side. Repeated extension, check or adjust, check until you find a solution to meet the problem requirements, will be designed. Retrospection method finds a solution algorithm: {INT M = 0, OK = 1; int N = 8; do {if (ok) extension; ELSE adjustment; OK = rationality of the previous M intense fill;} while (! OK || M! = N) && (M! = 0)) IF (M! = 0) Outputs; ELSE Output No report;} If the program is looking for all solutions, then after the decision will be found It should continue to adjust the integer fill in the last position and try to find the next solution. The corresponding algorithm is as follows: The algorithm for the retrospect list: {INT M = 0, OK = 1; int N = 8; do {if (ok) {if (m == n) {output solution; adjustment;} else Expansion;} else adjustment; OK = check the rationality of the previous M intense fill;} while (m! = 0);} To ensure that the program can terminate, adjustment must ensure that the exquisite fill sequence will not be again Experiments, that is, the required filling sequence is required to generate a model. The candidate given is set to form a candidate one by one in this order and test. From small to large or from large to small, it is possible to use. For example, when expanding, first fill in an integer 1, adjust, to find an integer that has not been used in the current candidate solution. The above expansion, adjustment, and inspection are written as procedures, see the procedures for all solutions to find all the solutions. [Program] # clude 0) RETURN-1 B [A [POS]] = 1; A [POS] = J; B [J] = 0; Return Pos;} Void Find () {INT OK = 0, POS = 0; a [POS ] = 1; B [A [POS]] = 0; Do {IF (OK) f (POS == 8) {Write (A); POS = Change (POS); Else Pos = Extend (POS); ELSE POS = CHANGE (POS); OK = Check (POS);} while (pOS> = 0)} void main () {INT i; for (i = 1; i <= n; i ) B [i] = 1 Find ();} [Question] N Queens Problem Description: Ask all the layout of the Queen "Queen" on a N × N board to place n cannot capture each other. This is a question from chess. Queen can capture each other in four directions along the vertical and two slashes. As shown in the figure, an queen placed in the 3rd column of the 4th line of the board, and the Queen on the "×" position can capture each other with this queen. 1 2 3 4 5 6 7 8 × × × × × × × × × × × × × × × × × × × × × × × can get the following inspiration from the map: a suitable solution is Column, only one queen on each line, and there is only one queen on a slash. The solve process starts from the air configuration. On the basis of the rational configuration, the first list is column M 1 column, until the N-column configuration is also reasonable, it will find a solution. Then change the N-column configuration and want to obtain the next solution. In addition, in any column, there may be n types. When it is configured in Chapter 1, when changing, select Chain 2, line 3, ... until the Nth line. When the N-line configuration is not found, it is necessary to turn back to change the configuration of the previous column. The algorithm for solving the Queen is as follows: {Enter the checker size value n; m = 0; good = 1; do {if (good) if (m == n) {output solution; change, form the next candidate;} else expands the current candidate to the next column ELSE changes, form the next candidate; good = check the rationality of the current candidate;} WHILE (M! = 0);} Before writing the program, first determine the data structure of the side checkerboard. A more intuitive method is to adopt a two-dimensional array, but it will find that this representation will bring difficult to adjust candidate and inspect their rationality. A better way is to directly represent those common information as much as possible. For this question, "common information" is not a specific location of the queen, but "whether an Queen has been reasonably placed in a certain row and a slash." Because of the queen in a certain column, introduce a one-dimensional array (col []), value col [i] means a queen in the Queen of COL [i] in the chess board For example: col [3] = 4, it means that there is a queen on the 4th line in the third column of the board. In addition, in order to make the program after receiving all the detrogenic to the initial position, the initial value of the set of col [0] is 0 when retracting to 0, and the program has been completed, and the program is running. In order to make the procedure simple and convenient in checking the rationality of the Queen's configuration, the following three work arrays: (1) array a [], a [k] means that there is no queen on the row; (2) array B [], B [K] indicates that there is no queen on the left and left low oblique lines of the row; (3) array C [], C [K] indicates that the row is left on the left and right low oblique lines; the chessboard is in the same right high left The checkered in low oblique lines, the sum of their line numbers and columns; the same left high and low-lateral checkered lines, their line numbers are the same as the difference. At the beginning, there is no queen on all rows and slashes, from the first line of the first line, the first queen begins, and placed a reasonable queen after the row col [M] line, ready to investigate the M When 1 column, in the array a [], b [] and c [], the position of the column is set to the position of the col [m] row; when it is traced back to the M-1 column from the M-M column, and Preparing to adjust the Queen Configuration of the M-1 column, clear the Queen's logo on the M-1 column, col [m-1] in the array, column, col [m-1]. An Queen is in M columns, col [m] rowner configuration is reasonable, determined by the array a [], b [] and c [] corresponding to the corresponding position. See the following procedures: [Program] # include [Program] # include [Program] # Define MaxN 20 INT N; INT COL [MAXN 1], A [MAXN 1], B [2 * MaxN 1], C [2 * MAXN 1]; Int Queen_one (int K, int K, int n) {INT I, FOUND; I = FOUND = 0; While (! Found && i [Problem] Packing Problem Description: The packing problem can be briefly summarized as follows: N items numbered 0, 1, ..., N-1, V0, V1, ..., VN-1, respectively. The N items are loaded into a plurality of boxes of V. It is contemplated that the volume of the N items does not exceed V, that is, for 0 ≤ n, there are 0 If you examine all subsets of n or less than N items into N or less than N items, the optimal solution can be found. But all the total number of possible divisions is too large. For appropriate N, find out that the possible division is expected to be affected. To this end, a very simple approximate algorithm is used for the packing problem, namely greed. The algorithm sequentially puts the item in the box that can be put in, although the algorithm cannot be guaranteed to find the best solution, but it still finds a very good solution. Without a generality, the volume of the N item is in order from large to the small row, that is, V0 ≥ V1≥ ... ≥ Vn-1. If the above requirements are not met, as long as the N item is first sorted from the size of their volume, then re-numbered the item according to the ordering result. The packing algorithm is simple to describe as follows: {Enter the volume of the box; Number of inputs N; in size from large to small order, enter the volume of each item; preset box chain is empty; preset has been used box counter Box_count is 0; for (i = 0 I [Program] # include Link = p;}} printf ("a total of% D box", Box_count); Printf ("All boxes are equipped with the following:"); for (j = Box_h, i = 1; J! = null; J = J-> Next, I ) {Printf ("The% 2D box, the remaining volume% 4d, the item is; / N", I, J-> Remainder; for (p = j-> head; p! = null; p = p-> link) Printf ("% 4D", P-> VNO 1); Printf ("/ n");}}} [problem] Major traversal problem Description: at 8 × 8 On the checkered board, start from any designated checker, find a path to the chessboard and only once. The horse is in a checkered, and there are up to 8 different locations reaching in one step, as shown. If the two-dimensional array BOARD [] [] means the checkerboard, its element records the step number when the horse is passed through this position. Another eight possibility of the horse (called method) set a order, such as the current location in the board (i, j) checkered, the next possible location is (i 2, j 1) (I 1, j 2), (i-1, j 2), (i-2, j 1), (i-2, j-1), (i-1, j-2) (I 1, j-2), (i 2, j-1), the actual location is within the position that has not yet passed and the position of the boundary. In order to facilitate the procedure of the program, two arrays can be introduced to store various vertical and horizontal increments of the current position, respectively. 4 3 5 2 Ma 6 1 7 0 For this question, the backtracking method can generally be used. Here is a WARNSDOFF policy. This is also a greedy method. It chooses the greedy standard for the next export to the location where you are allowed, choose Exit The least that position. If the current location (i, j) is only three exits, they are positions (i 2, j 1), (i-2, j 1) and (i-1, j-2), such as respectively Go to these locations, these three locations will have different exits, assume that the number of exports of these three locations is 4, 2, 3, respectively, the program will choose to let the horse go (I-2, J 1) position. Since the program uses a greedy method, the entire finding process is always forward, there is no backtrack, so I can find the solution very quickly. However, for some beginning, it is actually solved, and the algorithm cannot find solutions. For the case where the solution is not found, the program can only change the selection order of 8 possible exports, you can find the solution. Changing the exit selection order is to change the selection standard when there is the same exit. The following procedures are taken into account that the variable START is introduced to control 8 possible selection sequences. At the beginning of 0, when you can't find a solution, let Start add 1, re-find. Details The following procedures. [Program] # include Start ;} while (step <= 64) for (i = 0; i <8; i ) {for (j = 0; j <8; j ) Printf ("% 4d", Board [i] [j]) PRINTF ("/ n / n");} scanf ("% * c");}}} 7. The basic idea of the grahe method is the calculation time required to use computer solving problems. Related to its size N. The smaller the problem, the easier directly solve, the less calculation time required for the problem. For example, for the sorting problem of n elements, when n = 1, no calculation is required; n = 2, as long as the comparison can be arranged in order; n = 3, as long as it is compared to 3 times, .... When N is large, the problem is not so easy to handle. To solve a larger problem directly, it is sometimes difficult. The design idea of grasping method is to divide a large problem that is difficult to solve, divided into some smaller the same problem, so that all breaks, divide them. If the original problem can be divided into k sub-problems (1 2. The problems that can be solved by the applicable condition of the grahe method can generally have the following characteristics: (1) The scale of this problem can be easily resolved to a certain degree; (2) This problem can be decomposed into several The same problem is the same, that is, the problem has the most optional nature; (3) the solution of the sub-problem that utilizes this problem can be merged into this problem; (4) the various subsets decomposed by the problem The problem is independent of each other, that is, the child is not included with a public sub-child problem. The above first feature is most of which can be satisfied, because the computational complexity of the problem is generally increased with the increase in the scale of the problem; the second feature is the premise of the application of grants, it is also most problems. It can be met, this feature reflects the application of recursive ideology; the third feature is the key, it can use the granted method to be fully dependent on whether there is a third feature, if there is a first and second characteristics, and If you do not have a third feature, you can consider greedy or dynamic planning. Article 4 The characteristics involve the efficiency of the grahe method, if each sub-problem is not independent, the grahe method must be a lot of unnecessary work, repeat the public sub-problem, at this time, although it can be used, but general It is better to use dynamic planning. 3, the basic steps of the grahe method are three steps in each layer: (1) Decomposition: Decompose the original problem into several scale, independent, independent, and the same subprocess as the original problem; (2) Solution: If the son problem is small and it is easy to solve, it is directly solved. Otherwise, each sub-problem is recursively understood; (3) Merge: Combine the composition of each sub-problem and the solution. Its general algorithm design pattern is as follows: Divide_and_conquer (P) IF | P | ≤n0 Then Return (Adhoc (P)) Drake P Decomposed into less child problems P1, P2, ..., PK for i ← 1 to k DO yi ← Divide-And-Conquer (PI) △ Recursive Solution PI T ← MERGE (Y1, Y2, ..., YK) △ Mr. Return (T) Where | P | Represents the size of the problem P; N0 is a threshold, indicated When the size of the problem P does not exceed N0, the problem is easy to solve directly, and it is not necessary to continue to decompose. ADHOC (P) is the basic sub-algorithm in the grahe method for direct solution to a small scale P. Therefore, when the size of P does not exceed N0, the algorithm Adhoc (P) is solved directly. Algorithm MERGE (Y1, Y2, ..., YK) is the combined sub-algorithm in the grahe method, used to combine the corresponding solutions of P1, P2, ..., and PK of the Pk. Solution. According to the segmentation principle of the grahe method, how many sub-problems should be divided? How should the scale of each sub-problem be appropriate? These problems have been hard to answer. However, in a large number of practices, it is best to make the scale of the sub-problem substantially the same time when designing the algorithm with the granted method. In other words, the processing method of dividing a problem with k sub-problem equally equally equal is effective. Many problems can take K = 2. This approach to which this makes the sub-problem is approximately a balanced sub-problem, it is almost always good than the scientific scale. The merge step of the grahe method is the key to the algorithm. Some problems have a more obvious merger, and some problem mergers are more complicated, or there are a variety of mergers; or the merge scheme is not obvious. How to merge, there is no unified mode, and the specific problem is required. [Problem] Grand Integer Multiplication Description: Typically, when analyzing a calculation complexity of an algorithm, the addition and multiplication operations are treated by basic operations, and the calculation time required to perform a addition or multiplication is as one Depending on the constant of the computer hardware processing speed. This assumption is reasonable only if the computer hardware can directly represent and process the integer of the operation. However, in some cases, we have to handle a large integer, which cannot be processed within the range that the computer hardware can directly represent. If it is represented by floating point, it can only be approximately indicative of its size, and the valid numbers in the calculation result are also limited. To accurately represent a large integer and require a number on all digits on the calculation result, you must use the software method to implement a big integer arithmetic operation. Please design an effective algorithm to make two N-bit multiplier multiplication. Setting x and y are n-bit binary integers, and now calculate their product xy. We can design a method of calculating the product XY, but there is too much efficiency in this way. If each 2 1-digit multiplication or addition is a step operation, then this method is to be o (n2) step to obtain the product XY. Here we use the granted method to design a more efficient large integer product algorithm. Figure 6-3 Big integer x and y We divide the n-bit binary integers x and y each section into 2 segments, the length of each section is N / 2 (for simplicity, assuming N is 2 power), As shown in Figure 6-3. Thus, x = A2N / 2 B, Y = C2N / 2 D. Thus, the product of X and Y is: XY = (A2N / 2 B) (C2N / 2 D) = AC2N (AD CB) 2N / 2 BD (1) If XY is calculated in formula (1), then We must perform multiplication (AC, AD, BC, and BD) of N / 2-bit integers, and 3 times not more than N-bit integer addition (corresponding to the plus sign in equation (1), etc. 2 times shift (respectively, 2n and 2n / 2) of the formula (1)). All of these additions and shifts share O (n) step operations. Set t (n) is the total number of computables required by two N-bit integers, and we have: (1), we have: (2) This can be obtained to T (n) = O (N2). Therefore, the product of X and Y is not more effective than the product of X and Y is more effective than the method of primary school. To improve the calculation complexity of the algorithm, you must reduce the number of multiplication. To this end, we write XY to another form: XY = ac2n [(ab) (DC) AC BD] 2N / 2 BD (3) Although, equation (3) seems to be complex (1), but it only needs to do 3 N / 2 Integer multiplication (AC, BD, and (AB) (DC)), 6 addition, subtraction and 2 shifts. Therefore: (4) Use the formula method for decryption equation to immediately solve it to T (N) = O (NLOG3) = O (N1.59). Using the equation (3), and considering the effects of X and Y symbols on the results, we give the full algorithm of the multiplication of large-scale multiplication MULT as follows: Function MULT (X, Y, N); {x and y are integers of 2 N, return result is the product XY} begin s = Sign (x) * Sign (Y); {S is X and Y's symbol product} x = ABS (x); y = abs (y); {x and y take absolute value} if n = 1 Then IF (x = 1) and (y = 1) THEN RETURN (s) Else Return (0) Else Begin A = X left side N / 2 bits; b = x right n / 2 bits; C = Y, the left side N / 2 bits; D = Y, the right side N / 2 bits; ml = MULT (A, C, N / 2); M2 = MULT (AB, DC, N / 2); M3 = MULT (B, D, N / 2); S = S * (M1 * 2N (M1 M2 M3 * 2N / 2 m3); RETURN (S); END; END; The binary integer multiplication can also be applied to the multiplication of the decimal integer to improve the number of multiplication. [Problem] The closest point is a description of the problem: In the application, simple geometric objects such as points, circles are commonly used representatives in the real world. In the issue involving these geometric objects, information is often required to understand other geometric objects in its neighborhood. For example, in the air traffic control problem, if the aircraft is taken as a point in the space, the two aircraft with the largest collision risk is the closest point in this space. Such problems are one of the basic problems of research in geometry. Below we focus on the closest point on the plane. The closest point to the problem is: the N points on a given plane, find a pair of points, so that in all directions of N points, the point pair is minimized. Strictly speaking, the closest point may be more than 1 pair. For the sake of simplicity, it is limited to one pair of findings. This problem is easy to understand, and it seems that it is not difficult to resolve. As long as we calculate each point from the distance from other N-1 points, we can find two points to achieve the minimum distance. However, this is too low, and the calculation time is required for o (N2). Whether we can find an O (NLOGN) algorithm. This problem clearly meets the first and second applicable conditions of the granted method. We consider dividing the set S of N points on the plane into two subsets S1 and S2, and about N / 2 points in each subset. Then, then recursively seek the closest point pair in each subset. Here, a key problem is how the merger step in the granted method, that is, how the closest point pair in the original set S is obtained by the closest point pair of S1 and S2, because the closest point of S1 and S2 The closest point pair that is not necessarily S is not. If the two points of the closest point pair of compositions S are in S1 or in S2, the problem is easy to solve. However, if these two points are in S1 and S2, the maximum number of N / 2 points in S1 is mostly N / 2 points in S1, respectively, and the N2 / 4 calculation is still required. And compare can determine the closest point pair of S. Therefore, according to this idea, the merge step consumption is O (N2). The calculation time t (n) required for the entire algorithm should be satisfied: T (n) = 2T (N / 2) O (N2) It is determined to t (n) = O (N2), that is, the time consumption with the merge step, the method of displaying is better than using exhaustion . From the set of formula law from the decipherent equation, we see that there is too much time when the problem is consumed. This inspires that we put the attention on the merge step. In order to make the problem easy to understand and analyze, we will first consider one-dimensional situation. At this time, N points are degraded into N solids x1, x2, ..., xn on the X-axis. The closest point is two real numbers that are different from the N implementings. We will apparent that X1, X2, ..., XN will be sequenced first, then, you can find the closest point pair with a linear scan. This method mainly calculates that time spent in sort, thus demonstrated in the sorting algorithm, time consumption is O (NLOGN). However, this method cannot be directly extended to two-dimensional situations. Therefore, in the simple case of this one-dimensional, we still try to solve the granted method and hope to promote the two-dimensional situation. Suppose we divide S with a point m on the X-axis to two subsets S1 and S2 such that S1 = {x ∈S | x ≤ M}; S2 = {x∈S | x> m}. In this way, there is P Figure 1 Minimal level of one-dimensional situation We note that if the closest point of S is {P3, Q3}, ie | P3-Q3 | <Δ, the distance between P3 and Q3 and M does not exceed δ, That is, | P3-M | <Δ, | Q3-M | <δ, that is, P3 ∈ (m, m), Q3 ∈ (m, m δ). Since the semi-closed interval of each length is δ contains to a point (otherwise there must be a two-point distance of less than δ), and M is the split point of S1 and S2, so (m-Δ, m) is included in the present A point in s. In the same way, (m, m δ) is also included in a point in S. As can be seen from Fig. 1, if there is a point in (m-δ, m), this point is the greatest point in S1. Similarly, if there is a point in S in (m, m δ), this point is the minimum point in S2. Therefore, we can find a bit of the interval (M-δ, M) and (M, M δ) in linear time, namely P3 and Q3. Therefore, we can use the solution and S2 of S1 with the linear time and become the solution of S. That is, according to this granting strategy, the synthesis step can be completed in O (n) time. Do you have a valid algorithm? There is also a problem that needs to be seriously considered, that is, the selection of the split point M, and the division of S1 and S2. One basic requirement for selecting the split point M is thus derived a linear division of the set S, ie s = S1∪s2, S1∩S2 = φ, and S1 {x | x ≤ M}; s2 {x | x> m} . It is easy to see that if M = [MAX (S) Min (s)] / 2 is selected, the linear segmentation can be met. After selecting the split point, then the S is divided into S1 = {x∈S | x ≤ M} and S2 = {x ∈S | x> M}. However, such a segmentation point M is selected, it is possible to cause the imbalance of divided subsets S1 and S2. For example, in worst cases, | S1 | = 1, | S2 | = N-1, the resulting grade method to calculate the calculation time t (n) required in the worst case, should meet the recursive equation: t (n ) = T (N-1) O (n) Its solution is T (n) = O (N2). This phenomenon of this efficiency can be resolved by the method of "balance sub-problem" in division. That is, we can appropriately select the split point M, so that there are substantially equal number of points in S1 and S2. Naturally, we will think of the median number of coordinates of the N points of s. The linear time algorithm for selecting the number of bits described in the selection algorithm allows us to determine a balanced split point M within the o (n) time. At this point, we can design a algorithm of the closer point to the closest point of the point set S. Float Pair (s); {if | s | = 2 Δ = | x [2] -X [1] | /*X[1..n] is stored in the N point coordinate * / else {if (| S | = 1) δ = ∞ ∞ ∞ {= s The median value of the coordinate value of each point; constructs S1 and S2, so that S1 = {x∈S | x ≤ M}, S2 = {x∈S | x> m}; Δ1 = pair (S1); Δ2 = pair (S2); p = max (S1); q = min (S2); Δ = min (Δ1, Δ2, QP);} return (Δ) The above analysis can be seen that the division step of the algorithm and the total share of the merged step O (N). Therefore, the calculation time t (n) consumed by the algorithm is satisfied: Solution This recursive equation can be t (n) = O (nlogn). [Question] Cycling schedule problem description: The N = 2K athletes must be played in the tennis cycle. Now design a game schedule to meet the following requirements: (1) Each player must be once again with other N-1 players; (2) Every player can only participate once a day; (3) cycle in N-1 The end of the day. Please press this request to design a table with N rows and N-1 columns. In the first line in the table, the third player is filled with the players encountered in JINs. Where 1 ≤ i ≤ N, 1 ≤ j ≤ N-1. According to the grahe policy, we can divide all the players into two halves, and the N-player game schedule can be determined by the N / 2 players. Recursively use this one-to-two strategy to divide the players until only two players are left, the development of the game schedule is very simple. At this time, just make these two players to play. 1 2 3 4 5 6 7 1 2 3 4 5 6 7 8 2 1 4 3 6 7 8 5 3 4 1 2 7 8 5 6 1 2 3 4 3 2 1 8 5 6 7 1 2 3 4 5 6 7 8 1 4 3 2 1 2 1 4 3 6 5 8 7 2 1 4 3 1 2 3 4 1 2 7 8 5 6 3 2 1 4 2 1 4 3 2 1 8 7 6 5 4 3 2 1 (1) (2) (3) Figure 1 2, 4 and 8 players' game schedule Figure 1 The square surface (3) listed in the eight players are the game schedule. The upper left corner and the two small pieces of the lower left corner are the players 1 to players 4 and players 5 to players 8 for 3 days. According to this, all the numbers in the upper left corner small block are copied in the lower right corner accordingly, and all the numbers in the lower left corner block are copied in the upper right corner according to their relative position, so that we will arrange 1 to 1 Players 4 and players 5 to players 8 in the next 4 days. This idea is easy to extend this game schedule to the situation with any number of players. 8. Dynamic planning methods often encounter complex problems that cannot be simply decomposed into several sub-problems, and will decompose a series of sub-problems. Simply use a method of decomposing a problem with a sub-problem, and the solution to the solution to the solution, the problem will increase when the problem is increased. In order to save the same amount of the same sub-problem, an array is introduced, regardless of whether they are for final solution, solving all sub-problems in this array, this is the basic method used by the dynamic planning method. The following uses an example to illustrate the use of dynamic planning methods. [Problem] For the longest common character subsequence of two character sequences: The subsequence of the character sequence refers to the number of characters (may not be removed) from a given character sequence (may not be removed) The character sequence formed. Let the given character sequence x = "x0, x1, ..., xm-1", sequence y = "Y0, Y1, ..., YK-1" is the subsequence of X, and there is a strict incremental subscript sequence of X < I0, I1, ..., IK-1> make all J = 0, 1, ..., k-1, with xij = Yj. For example, x = "abcbdab", y = "bcdb" is a subsequence of X. Given two sequences A and B, the sequence z is a common subsequence of A and B, refers to the subsequences of A and B. The problem requires the longest common subsequence of two sequences A and B. If all subsequences listed in A, the subsequences of the b is employed, and the subsequences of the subsequent sequences are detected, and the resulting subsequences are recorded, the longest common subsequence is finally obtained. This method is too much time consumption. Consider how to decompose a sub-problem for the longest public subsequence, set a = "A0, A1, ..., AM-1", B = "B0, B1, ..., BM-1", and z = "Z0, Z1, ... ZK-1 "for their longest common subsequences. It is not difficult to prove that there is the following nature: (1) If AM-1 = BN-1, ZK-1 = AM-1 = BN-1, and "Z0, Z1, ..., ZK-2" is "A0, A1, ..., AM-2" and A maximum common subsequence of "B0, B1, ..., BN-2"; (2) If AM-1! = BN-1, if ZK-1! = AM-1, Implication "Z0, Z1, ... , ZK-1 "is a longest common subsequence of" A0, A1, ..., AM-2 "and" B0, B1, ..., BN-1 "; (3) If AM-1! = BN-1, if ZK-1! = BN-1, Implication "Z0, Z1, ..., ZK-1" is "A0, A1, ..., AM-1" and " One of the longest common subsequences of B0, B1, ..., BN-2. In this way, when finding a and b, if there is AM-1 = BN-1, further solve a child problem, find "A0, A1, ..., AM-2" and "B0, B1, ..., One of the longest public subsequences of BM-2; if AM-1! = BN-1, we must solve two child problems, find "A0, A1, ..., AM-2" and "B0, B1, ..., One of the longest common subsequences of BN-1 and finds a maximum public subsequence of "A0, A1, ..., AM-1" and "B0, B1, ..., BN-2", and then takes two The longer member is the longest common subsequence of A and B. Definition C [I] [J] is the length of the longest common subsequence of sequence "A0, A1, ..., AI-2" and "B0, B1, ..., BJ-1", calculate C [I] [J] Recountedly expressed as follows: (1) C [I] [j] = 0 If i = 0 or J = 0; (2) C [i] [j] = C [i-1] [j-1] 1 If i, j> 0, and A [i-1] = b [j-1]; (3) C [i] [j] = max (C [i] [j-1], C [i-1] [j]) If I, J> 0, and A [i-1]! = B [J-1]. According to this calculation, the length function of the longest common subsequence of two sequences can be written. Since C [I] [J] is only dependent on C [I-1] [J-1], C [I-1] [J] and C [I] [J-1], so it can be from C [ m] [n] Start, track the generation process of C [I] [J], and the longest common subsequence is reversed. See the details. # include Figure 2, for example, if the routes i and j are the optimal path of A to C, depending on the optimization principle, the route J is the optimal route from b to c. This can be proven to be proven to be proven: assuming that another path J 'is the optimal path of B to C, then the route of A to C takes I and J' than I and J, contradictory. Thus, J 'must be the optimal path of B to C. The optimization principle is the basis of dynamic planning, any problem, if the support of the optimization principle is not possible, it is impossible to calculate the dynamic planning method. Dynamic planning basic equations based on optimization principles are basic methods to solve all dynamic planning issues. (2) Non-rearwardness will be arranged in each stage, and for a given stage state, the status of each stage cannot directly affect its future decisions, but can only pass the current state. In other words, each state is a complete summary of past history. This is no rear direction, also known as there is no effect. (3) The key to the superimposed dynamic planning algorithm of child problems is to solve redundancy, this is the fundamental purpose of dynamic planning algorithm. Dynamic planning is essentially a technique in spatial transfer time, which has to store various states in the process in the process of implementation, so its spatial complexity is greater than other algorithms. Selecting the dynamic planning algorithm is because the dynamic planning algorithm can bear in space, and the search algorithm cannot be spaced at time, so we take time. Therefore, there is also a significant feature of the problem that can be solved with dynamic planning: the overlap of the child. This nature is not a necessary condition for dynamic planning, but if the nature cannot meet, the dynamic planning algorithm does not have advantages compared to other algorithms. 2. The basic idea of dynamic planning mainly introduces some of the theoretical basis for dynamic planning, and we will show the dynamic plan of the above-mentioned obvious stage division and state transfer equation called standard dynamic planning, this standard dynamic plan is studying The multi-stage decision issues are derived, with strict mathematical forms, suitable for theoretical analysis. In practical applications, the phase division of many problems is not obvious, and if it is deliberately divided by the phase method. In general, as long as the problem can be divided into a smaller child problem, and the best solution of the original problem contains the best solution of the child problem (ie, the most desirable principle), can consider the use of dynamic planning . The essence of dynamic planning is to grants thoughts and solve redundancy. Thus, dynamic planning is a sub-problem that decomposes problem instances into smaller, similar sub-problems, and solves the repetitive child problem. Algorithm strategy for optimization problems. It can be seen that the dynamic planning method is similar to the granted method and greedy method, and they are induced by the problem instance into smaller, similar sub-problems, and produce a global optimal solution by solving the problem. Among them, the current choice of greed can rely on all the options that have been made, but do not rely on the choices and sub-problems they have to do. Therefore, the greedy method is topped downwards, and a greedy choice will be made step by step; while the various sub-issues in the grahe method are independent (ie, the public sub-problem is not included), so once the subsequent problem is obtained. It is possible to solve the solution of the subprocess from the solution. However, it is not enough, if the current choice may have a problem that may rely on sub-problem, it is difficult to achieve the global optimal solution through local greed; if each sub-problem is not independent, the rule of control must do many unnecessary work, Repeat the public subprocess. Solving the above problems is to use dynamic planning. This method is primarily applied to optimization problems, which will have a variety of possible solutions, each solution has a value, and dynamic plan finds the solution of the optimal (maximum or minimum) value. If there are several solutions to take the best value, it only takes one of them. During the solution, the method is also the solution to the global optimal solution by solving the partial problem, but is different from the granted method and greedy. Dynamic planning allows these sub-problems to be not independent, (ie, each child problem can be included) Public sub-issues also allow it to be selected by the solution of their own sub-problems, which is only solved by each child, and saves the results to avoid calculation every time you encounter. Therefore, the problem for the dynamic planning method has a significant feature, that is, the child problems in the sub-problem tree have exhibited a large amount of repetition. The key to the dynamic planning method is that for repeated child problems, only the first encounter is solved, and saves the answer, let the answer directly to the direct reference, do not have to resolve. 3. The basic steps of the dynamic planning algorithm are designed to design a standard dynamic planning algorithm, which can usually be carried out in the following steps: (1) Division phase: divide the problem into several phases. Note that such a certain stage must be ordered or can be sorted (ie, no post-pendant), otherwise the problem cannot be solved by dynamic planning. (2) Select Status: A variety of objective conditions in which problems develop to each stage are expressed in different states. Of course, the choice of state should be met without post. (3) Determine the decision and write the status transfer equation: The reason why the two steps are placed, because decision-making and state shift has natural links, state shift is based on the state and decision in the previous stage to derive the state of this phase. . So, if we identify the decision, the status transfer equation is written. But in fact, we often do it, determine the decision based on the relationship between the two adjacent numbers of states. (4) Write a planning equation (including boundary conditions): The basic equation of dynamic planning is a general formal expression of the planning equation. Generally speaking, this step is still relatively simple as long as the phase, state, decision making and state shift is determined. The main difficulty of dynamic plan is theoretically design, once design is completed, and the implementation is very simple. According to the basic equation of the dynamic plan, the optimal value can be recursively recursively calculated, but it is generally changed to a recurrent calculation, and the general framework implemented is as follows: Basic framework for standard dynamic plan 1. Initializing FN 1 (XN 1); {Border Condition} for K: = N Downto 1 Do for each xk∈xk do for each UK∈UK (XK) Do Begin 5 FK (XK): = One Element; {∞ or -∞} 6. xk 1: = TK (XK, UK); {State Transfer Equation} 7. T: = φ (FK 1 (XK 1 ), vK (xk, uk)); {Basic equation (9)} IF T is more optimal THEN FK (XK): = T; {calculation fk (xk) optimal value} END; 9 . T: = one extreme value; {∞ or -∞} for each x1 (x1) bit (x1) than T better THEN T: = f1 (x1); {according to 10-style optimal indicator } 12. Output T; However, the actual application often does not explicitly design dynamic planning in accordance with the above steps, but in the following steps: (1) Analyze the nature of the optimal solution and scrapen its structural characteristics. (2) Decarily define the optimal value. (3) The optimal value is calculated from the bottom-up mode or the auto-down memory method (memo method). (4) Constructs an optimal solution based on the information obtained when calculating the optimal value. Steps (1) ~ (3) are the basic steps of the dynamic planning algorithm. In the case where the optimal value is required, step (4) can be omitted, and if a problem is required, step (4) must be performed. At this time, when the optimum value is calculated in step (3), more information is usually required to quickly construct a optimal solution according to the recorded information in step (4). [Problem] Optimal Triangulation Problem Problem Problem Problem of Convex Polygon: The polygon is a segmental linear closure of the plane. That is, the polygon is composed of a series of first-tail line segments. The linear segments of the polygon are called the edges of the polygon. The connection point of the multilateral phase is referred to as a vertex of the polygon. If there is no other common point in addition to the vertices between the edges, the polygon is called a simple polygon. A simple polygon is divided into three parts: all points surrounded in the polygon constitute the internal interior of the polygon; the polygon itself constitutes the boundary of the polygon; the rest of the plane constitutes the exterior of the polygon. When a simple polygon is constituted, the simple polygon is called convex polygons. That is to say, all points on the linear segments of any two points in the convex polygon boundary or the internal direction are all in the internal or boundary of the convex polygon. Typically, a convex polygon is represented by the counterclockwise sequence of polygonal vertices, i.e., P = The problem of convex polygon optimal triangulation is: given a convex polygon P = Various powerful function ω can be defined on the triangle. For example: Defining ω (△ Vivjvk) = | Vivj | | Vivk | | VKVJ |, where | vivj | is a European Distance of Point VI to VJ. The optimal triangulation of this power function is the slice of length. (1) The optimal triangulation problem of the most excited polygonal polygonal polygon is the most excited sub-structural property. In fact, if a convex (N 1) edge P = (2) The recursive structure of the right triangular cross section corresponds, first, definition T [I, J] (1 ≤ i The value of t [i, j] can be calculated using the mostteficized child structure properties. Since the weight of the degraded 2 vertex polygon is 0, T [I, I] = 0, i = 1, 2, ..., n. When J 1 I≥1, the child polygon (3) Calculate the dynamic planning algorithm of the calculated convex (N 1) edge P = Design a solution to make the car pass through this highway as small as possible (the car is filled with oil). 2, the shortest path: There is a network, requiring the shortest path from a certain vertex to other vertices 3, hip horses: on 8 * 8 checkered board, starting from any designated square, looking for a walk The checkerboard is passed and only one path is passed. 4, the traversal of the binary tree 5, backpack problem 6, achieve two large integers by dividing 7, X1, X2, ..., XN is the N points on the straight line, to cover the closed interval of the unit length This n point, how many such unit closed intervals do you need? 8. When the relationship "<" and "=" will be arranged in sequence, there are 13 different order relationships: A = B = C, A = B The estimation method is as follows: v = C0 A1-A0 A1 = V A0-C0 V = C1 A0 A2-2A1 A2 = V 2A1-A0-C1 ...... .......... v = Ci ai- 1 AI 1-2AI AI 1 = V 2AI-AI-1-Ci is not desirable to obtain A0 to AN-1 accurately, but to do the following: If A0 is 0, it can be in accordance with the above A1 to AN-1 is calculated. The program finds the minimum of A and let all A values subtract this minimum, so that the number of sheets per pile of removal is greater than equal to 0. The actual operation uses the following greed strategy: (1) Search each pile each time, if you find that the sheet can be moved from the I, you will complete a move. That is, the nest of the i pile takes away from I to take a flakes. The number of sheets can be taken from the I pile slice to adjacent piles Number: If the I heap is in both end position (i = 0 i = N-1), require Ci> = Ai; if i pile is the middle heap, then Require Ci> = 2AI. (2) Due to all heaps of AI> 0, the number of sheets of the number of sheets is mostly the number of sheets taken away by its adjacent heap during the score. When the strategy (1) is searched, when there is no stack of removable sheets that do not satisfy the condition (1), this policy is adopted, and the number of sheets of the number of sheets is the same as the number of all of Ai> 0. Neighboring all the sheets of it. Author Blog: http://blog.9cbs.net/yuguanglou/