ida* Search Brief comparison with other search methods UVA11212 Editingabook

Source: Internet
Author: User

First of all, say IDs, on the DFS limit a layer limit maxd, if in the Maxd range did not find the solution, add maxd, continue to search.

When accessing the current node u, it is estimated to also search for the H (U) layer, and if H (U) + current layer D>maxd the time to prune, this is ida*.

Ida* belongs to DFS, when the node number of a layer in the state space is infinite, BFS fails, only DFS.

Compared to BFS, it occupies little space (no duplication required), and time efficiency is not low.

Note: The key to A * is to select the Valued function h ().

----------------------------------Split Line-------------------------------------------------------------

Speaking of UVA11212 Editingabook.

Strategies for narrowing the search space are

Strategy 1: Cut only the contiguous number fragments.

Strategy 2: Cut the fragment header to B for the end of a, or paste it behind the A-1, or paste it in front of the b+1.

Strategy 3: Do not break fragments that have been contiguous.

However, strategy 1 and Policy 2 can guarantee positive solutions: such as 5 4 3 2 1-"3 2 5 4 1-" 3 4 1 2 5-"1 2 3 4 5.

Strategy error is mainly due to neglect of the aftereffect, strategy 3 is possible, the continuous fragments as a whole, it must be more than the number of steps to disassemble it.

Find the valuation function below

Because each cut up to change 3 number of the previous (or successor), so the statistics before the number of incorrect numbers is n then only a few to search N/3 layer. If D+n/3>maxd is 3*d+n>maxd, then prune.

There is also a pruning: moving fragments b1~b2 to B2+1~c, which is equivalent to moving b2+1~c to the front of the b1~b2, so as long as the enumeration moves the fragment back to the line.

//Rey#include <bits/stdc++.h>Const intMAXN =9;intN,a[maxn];inlineBOOLEnd () { for(inti =1; I < n; i++){        if(A[i] <= a[i-1])return false; }    return true;} Inlineinth () {intCNT =0;  for(inti =1; I < n; i++)        if(A[i]! = a[i-1]+1) cnt++; returnCNT;}intMaxd;Const intIntsz =sizeof(int);Const intAsz =sizeof(a);BOOLDfsintd) {    if(3*d + H () >3*MAXD)return false; if(End ())return true; intOLD[MAXN];//Save amemcpy (Old,a,asz); intB[MAXN];//Shear Plate     for(inti =0; I < n; i++)if(i = =0|| Old[i]! = old[i-1] +1)//Strategy 3 Select the starting point for the longest continuous fragment cut     for(intj = i; J < N; J + +) {//endpoint and strategy 2 different selected fragments can be discontinuous         while(j+1< n && old[j+1] = = Old[j] +1) j + +;//Strategy 3memcpy (b,old+i,intsz* (j-i+1)); //Cut Moving Clips         for(intK = j+1; k < n;k++) {//because of the symmetry, just post it.             while(k +1< n && old[k+1] = = Old[k] +1) k++;//Strategy 3 does not destroymemcpy (a+i,old+j+1, intsz* (K-j)); memcpy (A+i+k-j,b,intsz* (j-i+1)); if(Dfs (d+1))return true; //Recoverymemcpy (A,old,asz); }    }    return false;} Inlineintsolve () {if(End ())return 0;  for(Maxd =1; Maxd <5; maxd++)        if(Dfs (0))returnMaxd; return 5;}intMain () {//freopen ("In.txt", "R", stdin);    intCas =0;  while(~SCANF ("%d", &n) &&N) { for(inti =0; I < n; i++) scanf ("%d", A +i); intAns =solve (); printf ("Case %d:%d\n",++Cas,ans); }    return 0;}

ida* Search Brief comparison with other search methods UVA11212 Editingabook

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.