Generally speaking, this is a very ⑨ problem, because:
(1) ⑨ a wall clock in the title
(2) There are ⑨ kinds of operation scheme
(3) This problem because the solution space is too small, can directly ⑨ heavy cycle!!
This problem can be solved efficiently with iterative deepening search, and the pruning strategy is also obvious:
The sequence of operations required by > must be monotonous and non-diminishing.
> The same operation cannot occur 4 times or more in the solution (Operation 4 times equals no operation)
Code:
1#include <cstdio>2#include <cstring>3#include <algorithm>4 5 using namespacestd;6 7 intdir[Ten]={0};8 intcmdcnt[Ten]={0};9 intans[Ten]={0};Ten One voidMoveint_cmd) A { -++Cmdcnt[_cmd]; - the Switch(_cmd) - { - Case 1: ++dir[1]; ++dir[2]; ++dir[4]; ++dir[5]; Break; - Case 2: ++dir[1]; ++dir[2]; ++dir[3]; Break; + Case 3: ++dir[2]; ++dir[3]; ++dir[5]; ++dir[6]; Break; - Case 4: ++dir[1]; ++dir[4]; ++dir[7]; Break; + Case 5: ++dir[2]; ++dir[4]; ++dir[5]; ++dir[6]; ++dir[8]; Break; A Case 6: ++dir[3]; ++dir[6]; ++dir[9]; Break; at Case 7: ++dir[4]; ++dir[5]; ++dir[7]; ++dir[8]; Break; - Case 8: ++dir[7]; ++dir[8]; ++dir[9]; Break; - Case 9: ++dir[5]; ++dir[6]; ++dir[8]; ++dir[9]; Break; - } - } - in voidUndoint_cmd) - { to--Cmdcnt[_cmd]; + - Switch(_cmd) the { * Case 1:--dir[1]; --dir[2]; --dir[4]; --dir[5]; Break; $ Case 2:--dir[1]; --dir[2]; --dir[3]; Break;Panax Notoginseng Case 3:--dir[2]; --dir[3]; --dir[5]; --dir[6]; Break; - Case 4:--dir[1]; --dir[4]; --dir[7]; Break; the Case 5:--dir[2]; --dir[4]; --dir[5]; --dir[6]; --dir[8]; Break; + Case 6:--dir[3]; --dir[6]; --dir[9]; Break; A Case 7:--dir[4]; --dir[5]; --dir[7]; --dir[8]; Break; the Case 8:--dir[7]; --dir[8]; --dir[9]; Break; + Case 9:--dir[5]; --dir[6]; --dir[8]; --dir[9]; Break; - } $ } $ -InlineBOOLisdest () - { the for(intI=1; i<=9; i++)if(Dir[i] &3)return false; - return true;Wuyi } the - BOOLSearch_aux (int_maxdepth,int_curdepth,int_lastcmd) Wu { - if(Isdest ())return true; About if(_curdepth > _maxdepth)return false; $ - for(inti=_lastcmd;i<=9; i++) - { - if(Cmdcnt[i] <3) A { + move (i); the BOOLNext=search_aux (_maxdepth,_curdepth+1, i); - undo (i); $ if(next) {++ans[i];return true; } the } the } the the return false; - } in the voidinput () the { About for(intI=1; i<=9; i++) scanf ("%d", dir+i); the } the the voidSearch () + { - for(intI=1;; i++)if(Search_aux (I,1,1))return; the }Bayi the voidPrintans () the { - for(intI=1; i<=9; i++) - while(ans[i]--) printf ("%d", i); the } the the intMain () the { - input (); the search (); the Printans (); the return 0;94}Cirno is willing to try this problem (*^__^*)
IOI1994 Beijing 2008 's Wall clock iteration deepened