Http://www.cppblog.com/MatoNo1/archive/2012/09/23/191708.html
———————————————————————————————————————————————————
General DFS (non-iterative) optimization methods are mainly:
(1) Feasibility pruning, if encountered can not produce a feasible solution to pruning, and sometimes, the feasibility of pruning can also refer to the search process for the exclusion of the non-legal situation;
(2) Optimization pruning: If it is not possible to produce a solution that is better than the present optimal solution to prune, including heuristic optimization pruning (i.e. branch gauge), the current solution of the progress of optimistic estimates, if the estimated value can not exceed the current optimal solution, then pruning;
(3) by changing the search order, the better solution can be obtained as early as possible, thus providing room for the pruning of the back;
(4) through pretreatment and other means, early to get the heuristic value or better solution, for the back of the pruning to provide leeway;
General steps:
(1) Preprocessing, of course, is written in the front, before the search to get inspiration value and so on;
(2) In the search process, first write the optimal pruning (including has reached the end of the search, it should also be judged, early elimination is not the optimal solution of the situation);
(3) Again determine the end of the search, if it is, do not immediately update the solution, but to determine whether the solution meets the requirements, and then update;
(4) If not to the end, then write the feasibility of pruning;
(5) The final write search process, including the need to change the search order situation.
Precautions:hierarchical problem of arrays.
This is a very serious problem, because layering errors are likely to cause some very strange errors to appear, which are difficult to find. In the debugging techniques of search questions, this issue has been mentioned, and the subject is involved.
In general, the array used during the search (including variables, which can be treated as a 0-dimensional array) can be divided into the following three categories:
(1) In the search process, only reference its value, will not modify the array (such as the preprocessing obtained in the east), equivalent to the constant;
(2) In the search process, it will change its value, but after the search is complete can be changed back to the original value of the array;
(3) In the search process, the value will be changed, and after the search is complete, the original value of the array is not changed back.
For arrays of type (1) (2), no layering is required, but for Class (3) arrays it must be layered. This is because these arrays in the multi-level search needs to be modified, and the search is finished and can not be changed, if not layered, then after the completion of the search, to continue to search the previous, the reference will be the value of the following, will be an error.
For the Class (3) array, some have "natural layering" (different elements for each layer of the search modification), such as r[][in the subject code], c[][]. However, there is no natural stratification, such as the subject of Len, pos[], tmp[, etc., so for these arrays, you need to add another dimension, for different layers using the dimension of different elements can be.
Here is the algorithm for the subject:
Use DFS to search for the bezel on each location. Search, first searched vertical and then search the horizontal, because the topic requires each connected block must be rectangular, so for the vertical, if the position of the top two adjacent position of the horizontal is not fully put (including only one), then the position of the vertical placement depends on the position of the upper row of the vertical there is no place (except the first row), If the two horizontal is put, then the vertical here can either put or not put (first search not put the case). Of course, there must be at least one vertical between the two 1 of a row, which is the feasibility limit. In the search of the horizontal, according to the line of the vertical, divided into a number of paragraphs, it is clear that each paragraph or below are covered with a horizontal seal, or not sealed. Wherein, if the segment is located in the connected block is 1, and the next line corresponding position also has 1, it must be sealed, if the segment is located in the connected block does not have 1, it can not be sealed (because there can not be a connected block in a 1 are not), otherwise you may choose to seal or not seal (of course, the first search This has been searched until the last line of the vertical, but also to determine whether the last line is not connected block 1, if not, it is a viable solution. Heuristic optimization: Set D[i] for the first row and after at least a few baffles (if a row has K 1, then at least (K-1) a vertical; If a column has K 1, then at least (K-1) a horizontal, add up can, obviously this is optimistic estimate), D[i] can be preprocessed, as the heuristic value.
"AHOI2013 revenge" from a topic the general steps of DFS and its optimization and the group layering problem "go"