楼主: cuicg

[SQL] 用SQL或PL/SQL求解数独,替三思发帖。

[复制链接]
论坛徽章:
520
奥运会纪念徽章:垒球
日期:2008-09-15 01:28:12生肖徽章2007版:鸡
日期:2008-11-17 23:40:58生肖徽章2007版:马
日期:2008-11-18 05:09:48数据库板块每日发贴之星
日期:2008-11-29 01:01:02数据库板块每日发贴之星
日期:2008-12-05 01:01:03生肖徽章2007版:虎
日期:2008-12-10 07:47:462009新春纪念徽章
日期:2009-01-04 14:52:28数据库板块每日发贴之星
日期:2009-02-08 01:01:03生肖徽章2007版:蛇
日期:2009-03-09 22:18:532009日食纪念
日期:2009-07-22 09:30:00
51#
发表于 2021-7-28 21:49 | 只看该作者
jihuyao 发表于 2021-7-28 02:29
Like bear picking corns I am less organized than 5th grader.  I almost make no links in most topics. ...

闲着也是闲着,你就把你做的贴出来看看嘛。

使用道具 举报

回复
论坛徽章:
0
52#
发表于 2021-7-30 01:56 来自手机 | 只看该作者
I browsed the web a little bit and found two topics new to me.  One is AI sudoku (absolutely no surprise lol) but it needs deep study?  How long it takes?  The other is equation sudoku.  Easy point with 9(row)+9(col)+9(box)=27 sets equations (all equals 45).  But can we easily pick out all independent equations with programming (eg 2 independent equations with 2 unknowns)???  With this uncertainty in logic it is hard to start any coding.

使用道具 举报

回复
论坛徽章:
0
53#
发表于 2021-9-4 13:54 | 只看该作者
newkid 发表于 2021-7-28 21:49
闲着也是闲着,你就把你做的贴出来看看嘛。

Googled sudoku forums and found this link for previous discussions
http://forum.enjoysudoku.com/sea ... 5003f014fe0d9b10791

Here just rewrite a pl/sql recursive funtion for brute force backtracking (though it is also possible to carry on str_array for forward tracking which I think performing better than backtracking).  Instead focus on the sudoku problem itself, I felt recently this brute force backtracking approach might be simply applied for the 最小生成树 as discussed recently (should be similar to sql with rownum=1 for depth first).  The logical flow is simply from start point and then choosing a direct connecting point in list and then next until reaching to the end point, and then going one level up to choose another point in list, etc.  It is probaly simpler than the sudoku process with well defined direct connections for each point.  Whenver a shorter path to the end point is found and stored in a global variable, more branches in following loopings could be quickly cut due to accumulated larger distance before reaching to the end point.  In fact if one inputs a desired (unreal) very small distance value (from start to end point) at the very begining, the recursive function may stop quickly after looping through only a couple of levels because all accumulated distances will go beyond the initial setup target value before all paths can even reach to end point.  So it would be critical to find an initial small path first for the brute force backtracking recursive function to perform well.  Anyway the recusive function has its own ineresting part in coding in procedural languages.  See if or not I can manage to write it for the shortest path problem (it would be intersting to comapre it with sql with rownum=1).


-----------------------------------------------

CREATE OR REPLACE PACKAGE pkg_sudoku
IS

   TYPE cha_array_1d IS TABLE OF char(1)
      INDEX BY PLS_INTEGER;

   TYPE cha_array_2d IS TABLE OF cha_array_1d
      INDEX BY PLS_INTEGER;

   TYPE cha_array_3d IS TABLE OF cha_array_2d
      INDEX BY PLS_INTEGER;

   type num_array_1d is table of number
      INDEX BY PLS_INTEGER ;

   type num_array_2d is table of num_array_1d
      INDEX BY PLS_INTEGER ;

   TYPE str_array_1d IS TABLE OF varchar2(500)
      INDEX BY PLS_INTEGER;

   TYPE str_array_2d IS TABLE OF str_array_1d
      INDEX BY PLS_INTEGER;

   function sol_sudoku(p_str IN long, out_arr IN OUT nocopy num_array_1d) return number ;

END pkg_sudoku ;
/

--===============================================================================

CREATE OR REPLACE PACKAGE BODY pkg_sudoku
IS

procedure peer_map(peer_arr IN OUT nocopy num_array_2d)
as

rid1 number ;
cid1 number ;
bid1 number ;
rid2 number ;
cid2 number ;
bid2 number ;
idx number ;

begin

for pos1 in 1..81 loop

        rid1 := ceil(pos1/9) ;
        cid1 := mod(pos1-1,9)+1 ;
        bid1 := ceil(cid1/3) + floor((rid1-1)/3)*3 ;

        idx :=0 ;

        for pos2 in 1..81 loop

                if pos2<>pos1 then
               
                        rid2 := ceil(pos2/9) ;
                        cid2 := mod(pos2-1,9)+1 ;
                        bid2 := ceil(cid2/3) + floor((rid2-1)/3)*3 ;

                        if rid2=rid1 or cid2=cid1 or bid2=bid1 then

                                idx := idx+1 ;                --upto 20 peers for each cell excluding self
                                peer_arr(pos1)(idx) := pos2 ;

                        end if ;

                end if ;

        end loop ;

end loop ;

end peer_map ;

-----------------------------------------------------------------------------

function update_peers(
str_arr                IN OUT        nocopy        str_array_1d,
flag_arr        IN OUT        nocopy        cha_array_1d,
peer_arr        IN OUT         nocopy         num_array_2d
) return number
as

rtn                number :=0 ;
peer_pos         number ;

begin

for pos in 1..81 loop

        if flag_arr(pos)='N' and length(str_arr(pos))=1 then

                for idx in 1..20 loop

                        peer_pos := peer_arr(pos)(idx) ;
                        str_arr(peer_pos) := replace(str_arr(peer_pos), str_arr(pos), '') ;

                end loop ;

                flag_arr(pos) := 'Y' ;
                rtn := 1 ;

        end if ;

end loop ;

return rtn ;

end update_peers ;

----------------------------------------------------------------------

procedure init_str_array(
p_str                 IN                 long,
str_arr                 IN OUT         nocopy        str_array_1d,
flag_arr        IN OUT         nocopy        cha_array_1d,
peer_arr        IN OUT  nocopy  num_array_2d
)
as

begin

--initialize str_arr and flag_arr
for pos in 1..81 loop

        flag_arr(pos) := 'N' ;
       
        if substr(p_str, pos, 1)>0 then

                str_arr(pos) := substr(p_str, pos, 1) ;

        else

                str_arr(pos) := '123456789' ;

        end if ;
       
end loop ;

--update peer cells for each filled cell
loop

        exit when update_peers(str_arr, flag_arr, peer_arr)=0 ;

end loop ;

end init_str_array;

-----------------------------------------------------------------------------------

function f_backtracking(
pos                 IN                number,
num_arr                IN                num_array_1d,
str_arr         IN OUT         nocopy         str_array_1d,
out_arr         IN OUT         nocopy         num_array_1d,
peer_arr        IN OUT  nocopy  num_array_2d
) return number
as

next_num_arr         num_array_1d :=num_arr ;       
next_pos         number ;
peer_pos         number ;
flag                 number ;

begin

for i in 1..length(str_arr(pos)) loop

        flag :=1 ;

        if length(str_arr(pos))>1 then

                --backtracking peer cells
                for idx in 1..20 loop

                        peer_pos := peer_arr(pos)(idx) ;

                        if peer_pos>=pos then

                                exit ;

                        else

                                if num_arr(peer_pos)=substr(str_arr(pos), i, 1) then

                                        flag :=0 ;
                                        exit ;

                                end if ;

                        end if ;

                end loop ;

        end if ;

        if flag=1 then

                next_num_arr(pos) := substr(str_arr(pos), i, 1) ;

                if pos = 81 then
                               
                        out_arr := next_num_arr ;
                        return 1 ;  --found valid solution!

                else

                        next_pos := pos+1 ;
                               
                        if f_backtracking(next_pos, next_num_arr, str_arr, out_arr, peer_arr)=1 then

                                return 1 ;

                        end if ;
                               
                end if ;

        end if ;

end loop;

return 0 ;

end f_backtracking ;

----------------------------------------------------------------------------------

function sol_sudoku(
p_str                 IN                 long,
out_arr         IN OUT nocopy         num_array_1d
) return number
AS

num_arr                num_array_1d ;
str_arr                str_array_1d ;
flag_arr        cha_array_1d ;
peer_arr        num_array_2d ;

begin

peer_map (peer_arr) ;

init_str_array(p_str, str_arr, flag_arr, peer_arr) ;

if f_backtracking(1, num_arr, str_arr, out_arr, peer_arr)=1 then

        return 1 ;

end if ;

return 0 ;
       
end sol_sudoku ;

--------------------------------------------------------------------------

END pkg_sudoku;
/

--=====================================================================================================

--run sql file below
--@c:\sudoku\sudoku_brute_force3

--=====================================================================================================

spool c:\temp\out.txt

set serveroutput on
set lines 200
set timing on


declare

tmp_str                long ;
input_str        long ;
output_str        long ;
output_arr        pkg_sudoku.num_array_1d ;

begin

input_str := '005300000800000020070010500400005300010070006003200080060500009004000030000009700' ;
--input_str := '1.......9.5.1...3...8..34...1.5.......9..8..2....6..7.3....4..8..2.......8..7..6.' ;
--input_str := '500600003000340000000509610392000760040000050007000004005800100003270000900001005' ;
--input_str := '8          36      7  9 2   5   7       457     1   3   1    68  85   1  9    4  ' ;
--input_str := '000000003001005600090040070000009050700000008050402000080020090003500100600000000' ;  --worst one!!! reverse input string and then run

input_str := replace(input_str, ' ', '0') ;
input_str := replace(input_str, '.', '0') ;

--reverse input string
/*
for i in 1..81 loop
        tmp_str := substr(input_str, i, 1)||tmp_str ;
end loop ;
input_str := tmp_str ;
*/

if pkg_sudoku.sol_sudoku(input_str, output_arr)=0 then
        dbms_output.put_line('no valid solution!') ;
end if ;

--display input
dbms_output.put_line(input_str) ;

--display output
for i in 1..81 loop
        output_str := output_str||output_arr(i) ;
end loop ;
dbms_output.put_line(output_str) ;

end ;
/

spool off

--=======================================================================================================



使用道具 举报

回复
论坛徽章:
407
紫蛋头
日期:2012-05-21 10:19:41迷宫蛋
日期:2012-06-06 16:02:49奥运会纪念徽章:足球
日期:2012-06-29 15:30:06奥运会纪念徽章:排球
日期:2012-07-10 21:24:24鲜花蛋
日期:2012-07-16 15:24:59奥运会纪念徽章:拳击
日期:2012-08-07 10:54:50奥运会纪念徽章:羽毛球
日期:2012-08-21 15:55:33奥运会纪念徽章:蹦床
日期:2012-08-21 21:09:51奥运会纪念徽章:篮球
日期:2012-08-24 10:29:11奥运会纪念徽章:体操
日期:2012-09-07 16:40:00
54#
发表于 2021-9-5 07:33 来自手机 | 只看该作者
程序太长了,效率怎么样?和newkid的对比一下

使用道具 举报

回复
论坛徽章:
407
紫蛋头
日期:2012-05-21 10:19:41迷宫蛋
日期:2012-06-06 16:02:49奥运会纪念徽章:足球
日期:2012-06-29 15:30:06奥运会纪念徽章:排球
日期:2012-07-10 21:24:24鲜花蛋
日期:2012-07-16 15:24:59奥运会纪念徽章:拳击
日期:2012-08-07 10:54:50奥运会纪念徽章:羽毛球
日期:2012-08-21 15:55:33奥运会纪念徽章:蹦床
日期:2012-08-21 21:09:51奥运会纪念徽章:篮球
日期:2012-08-24 10:29:11奥运会纪念徽章:体操
日期:2012-09-07 16:40:00
55#
发表于 2021-9-5 07:42 来自手机 | 只看该作者
没有装pg数据库,可以用https://sqliteonline.com/

使用道具 举报

回复
论坛徽章:
407
紫蛋头
日期:2012-05-21 10:19:41迷宫蛋
日期:2012-06-06 16:02:49奥运会纪念徽章:足球
日期:2012-06-29 15:30:06奥运会纪念徽章:排球
日期:2012-07-10 21:24:24鲜花蛋
日期:2012-07-16 15:24:59奥运会纪念徽章:拳击
日期:2012-08-07 10:54:50奥运会纪念徽章:羽毛球
日期:2012-08-21 15:55:33奥运会纪念徽章:蹦床
日期:2012-08-21 21:09:51奥运会纪念徽章:篮球
日期:2012-08-24 10:29:11奥运会纪念徽章:体操
日期:2012-09-07 16:40:00
56#
发表于 2021-9-5 07:55 来自手机 | 只看该作者
sql http://www.itpub.net/forum.php?mod=viewthread&tid=2140121&extra=page%3D8&mobile=2

使用道具 举报

回复
论坛徽章:
407
紫蛋头
日期:2012-05-21 10:19:41迷宫蛋
日期:2012-06-06 16:02:49奥运会纪念徽章:足球
日期:2012-06-29 15:30:06奥运会纪念徽章:排球
日期:2012-07-10 21:24:24鲜花蛋
日期:2012-07-16 15:24:59奥运会纪念徽章:拳击
日期:2012-08-07 10:54:50奥运会纪念徽章:羽毛球
日期:2012-08-21 15:55:33奥运会纪念徽章:蹦床
日期:2012-08-21 21:09:51奥运会纪念徽章:篮球
日期:2012-08-24 10:29:11奥运会纪念徽章:体操
日期:2012-09-07 16:40:00
57#
发表于 2021-9-5 08:33 来自手机 | 只看该作者
这是我收集的最快的版本


000000010400000000020000000000050604008000300001090000300400200050100000000807000
000000012000035000000600070700000300000400800100000000000120000080000040050000600
000000012003600000000007000410020000000500300700000600280000040000300500000000000
000000012008030000000000040120500000000004700060000000507000300000620000000100000
000000012040050000000009000070600400000100000000000050000087500601000300200000000


  1. #include <cstdio>
  2. #include <cstring>
  3. #include <ctime>
  4. const int XSIZE = 3;
  5. const int SIZE = XSIZE * XSIZE;
  6. const int MAX_C = SIZE * SIZE * 4;                    //最大列
  7. const int MAX_R = SIZE * SIZE * SIZE;                 //最大行
  8. const int MAX_SUDOKU = SIZE * SIZE;                   //数独矩阵大小
  9. const int MAX_LINK = MAX_C * MAX_R;                   //链表最大范围

  10. int L[MAX_LINK],R[MAX_LINK],U[MAX_LINK],D[MAX_LINK];  //抽象链表
  11. int C[MAX_LINK],O[MAX_LINK],S[MAX_C],H[MAX_R];        //C&O代表列&行,S每一列的节点数,H每一行的第一个节点
  12. int NodeNumber,RecordNumber;                          //用来指向节点
  13. int state[MAX_SUDOKU],ans[MAX_SUDOKU],record[MAX_SUDOKU];
  14. //////////////////////Dancing Links模版//////////////////////
  15. void init(void);        //Dancing Links的抽象链表初始化
  16. void insert(int,int);   //在链表的一个位置中添加标记
  17. void remove(int);       //删除一列,同时删除这一列中的行
  18. void resume(int);       //恢复一列,同时恢复这一列中的行
  19. //////////////////////Dancing Links模版//////////////////////
  20. bool input(void)
  21. {
  22.    char buffer[SIZE+1][SIZE+1];//留一个空间
  23.    if(scanf("%s",buffer[0])==EOF)   return false;
  24.    for(int i=1;i<SIZE;i++)
  25.       scanf("%s",buffer[i]);
  26.    memset(state,0,sizeof(state));
  27.    for(int i=0;i<SIZE;i++)
  28.       for(int j=0;j<SIZE;j++)
  29.          {
  30.             if(buffer[i][j]!='0')
  31.                state[i*SIZE+j]=buffer[i][j]-'0';
  32.          }
  33.    return true;
  34. }
  35.    char buffer2[SIZE*SIZE+3];//留一个空间给换行符
  36. bool input2(FILE* f)
  37. {
  38.    /*if(scanf("%s",buffer[0])==EOF)   return false;
  39.    for(int i=1;i<SIZE;i++)
  40.       scanf("%s",buffer[i]);*/
  41.    if(NULL== fgets(buffer2,SIZE*SIZE+2,f))
  42.      return false;
  43.    memset(state,0,sizeof(state));
  44.    for(int i=0;i<SIZE;i++)
  45.       for(int j=0;j<SIZE;j++)
  46.          {
  47.             //if(buffer[i][j]!='0')
  48.                state[i*SIZE+j]=buffer2[i*SIZE+j]-'0';
  49.          }
  50.    return true;
  51. }
  52. void add(int i,int j,int k)
  53. {
  54.    int row=i*MAX_SUDOKU+j*SIZE+k;
  55.    insert(row,i*SIZE+j+1);//注意
  56.    insert(row,i*SIZE+k+MAX_SUDOKU);
  57.    insert(row,j*SIZE+MAX_SUDOKU*2+k);
  58.    insert(row,(i/XSIZE*XSIZE +j/XSIZE)*SIZE+MAX_SUDOKU*3+k);
  59. }

  60. void build(void)
  61. {
  62.    int pos,row;
  63.    for(int i=0;i<SIZE;i++)
  64.       for(int j=0;j<SIZE;j++)
  65.          {
  66.             pos=i*SIZE+j;
  67.             if(state[pos]!=0)
  68.                {
  69.                 add(i,j,state[pos]);
  70.                }
  71.             else if(state[pos]==0)
  72.                {
  73.                   for(int k=1;k<=SIZE;k++)
  74.                      {
  75.                         add(i,j,k);
  76.                      }   
  77.                }
  78.          }   
  79. }

  80. bool dfs(int k)
  81. {
  82.    if(!R[0])
  83.       {
  84.          RecordNumber=k;
  85.          return true;   
  86.       }
  87.    int count=~(1<<31),c;
  88.    for(int i=R[0];i;i=R[i])
  89.       {
  90.          if(S[i]<count)
  91.             {
  92.                count=S[i];
  93.                c=i;
  94.                if(count==1)
  95.                   break;   
  96.             }  
  97.       }
  98.    remove(c);
  99.    for(int i=D[c];i!=c;i=D[i])
  100.       {
  101.          for(int j=R[i];j!=i;j=R[j])
  102.             {
  103.                remove(C[j]);   
  104.             }
  105.          record[k]=O[i];
  106.          if(dfs(k+1))
  107.             return true;
  108.          for(int j=L[i];j!=i;j=L[j])
  109.             {
  110.                resume(C[j]);   
  111.             }  
  112.       }
  113.    resume(c);
  114.    return false;
  115. }

  116. void output(void)
  117. {
  118.    for(int i=0;i<RecordNumber;i++)
  119.       {
  120.          ans[(record[i]-1)/SIZE]=(record[i]-1)%SIZE+1;
  121.       }
  122.    for(int i=0;i<SIZE;i++)
  123.       {
  124.          for(int j=0;j<SIZE;j++)
  125.             printf("%-2d",ans[i*SIZE+j]);
  126.          printf("\n");  
  127.       }
  128. }
  129. void output2(FILE* f )
  130. {
  131.    for(int i=0;i<RecordNumber;i++)
  132.       {
  133.          ans[(record[i]-1)/SIZE]=(record[i]-1)%SIZE+1;
  134.       }
  135.    for(int i=0;i<SIZE;i++)
  136.       {
  137.          for(int j=0;j<SIZE;j++)
  138.             fprintf(f,"%-2d",ans[i*SIZE+j]);
  139.          fprintf(f,"\n");  
  140.       }
  141. }
  142. int main()
  143. {
  144.    FILE *fp=fopen("sudoku17.txt","rt");
  145.    FILE *fo=fopen("sudoku17res.txt","wt");
  146.    while(input2(fp))
  147.       {
  148.          time_t start=clock();
  149.          init();
  150.          build();
  151.          dfs(0);
  152.          fprintf(fo,"%s\n",buffer2);
  153.          output2(fo);
  154.          fprintf(fo,"Time:%ldMs\n",clock()-start);
  155.       }
  156.       fclose(fp);
  157.       fclose(fo);
  158.    return 0;   
  159. }

  160. //////////////////////Dancing Links模版//////////////////////
  161. void init(void)
  162. {
  163.    for(int i=0;i<=MAX_C;i++)
  164.       {
  165.          L[i]=i-1;
  166.          R[i]=i+1;
  167.          U[i]=i;
  168.          D[i]=i;
  169.          C[i]=i;
  170.          O[i]=0;   
  171.       }
  172.    L[0]=MAX_C;
  173.    R[MAX_C]=0;
  174.    NodeNumber=MAX_C+1;
  175.    memset(S,0,sizeof(S));
  176.    memset(H,0,sizeof(H));
  177. }

  178. void insert(int i,int j)   
  179. {
  180.    if(H[i])
  181.       {
  182.          L[NodeNumber]=L[H[i]];
  183.          R[NodeNumber]=H[i];
  184.          L[R[NodeNumber]]=NodeNumber;
  185.          R[L[NodeNumber]]=NodeNumber;
  186.       }
  187.    else
  188.       {
  189.          L[NodeNumber]=NodeNumber;
  190.          R[NodeNumber]=NodeNumber;
  191.          H[i]=NodeNumber;
  192.       }
  193.    U[NodeNumber]=U[j];
  194.    D[NodeNumber]=j;
  195.    U[D[NodeNumber]]=NodeNumber;
  196.    D[U[NodeNumber]]=NodeNumber;
  197.    C[NodeNumber]=j;
  198.    O[NodeNumber]=i;
  199.    S[j]++;
  200.    NodeNumber++;
  201. }

  202. void remove(int c)
  203. {
  204.    L[R[c]]=L[c];
  205.    R[L[c]]=R[c];
  206.    for(int i=D[c];i!=c;i=D[i])
  207.       {
  208.          for(int j=R[i];j!=i;j=R[j])
  209.             {
  210.                U[D[j]]=U[j];
  211.                D[U[j]]=D[j];
  212.                S[C[j]]--;
  213.             }
  214.       }
  215. }

  216. void resume(int c)
  217. {
  218.    for(int i=U[c];i!=c;i=U[i])
  219.       {
  220.          for(int j=L[i];j!=i;j=L[j])
  221.             {
  222.                U[D[j]]=j;
  223.                D[U[j]]=j;
  224.                S[C[j]]++;
  225.             }
  226.       }
  227.    L[R[c]]=c;
  228.    R[L[c]]=c;   
  229. }
  230. /*
  231. 070680050
  232. 000000001
  233. 409507000
  234. 560000340
  235. 000000000
  236. 034000017
  237. 000703804
  238. 300000000
  239. 090015030
  240. */
复制代码

使用道具 举报

回复
论坛徽章:
0
58#
发表于 2021-9-9 14:50 来自手机 | 只看该作者
Brute force backtracking is like blind cat catching rat by chance.  It is probably optimizable like changing table join order which itself is tough too.  So apply more well defined logics like bared double/triples/x-wings is essential to eliminate cell candidate values as much as possible.  Is dancing link working like trial and error or like chain link forcing (Which I consider as the last logical resolve without guessing)?  In my experience with hard problems, all involve long range chain links after applying single:double:triple:x-wing.  I tried avoiding Oracle specific functions and therefore it can similarly coded in c for performance purpose.  The examples tested timing from 20ms to 50s, totally depending on luck.

使用道具 举报

回复
论坛徽章:
407
紫蛋头
日期:2012-05-21 10:19:41迷宫蛋
日期:2012-06-06 16:02:49奥运会纪念徽章:足球
日期:2012-06-29 15:30:06奥运会纪念徽章:排球
日期:2012-07-10 21:24:24鲜花蛋
日期:2012-07-16 15:24:59奥运会纪念徽章:拳击
日期:2012-08-07 10:54:50奥运会纪念徽章:羽毛球
日期:2012-08-21 15:55:33奥运会纪念徽章:蹦床
日期:2012-08-21 21:09:51奥运会纪念徽章:篮球
日期:2012-08-24 10:29:11奥运会纪念徽章:体操
日期:2012-09-07 16:40:00
59#
发表于 2021-9-15 15:11 | 只看该作者
本帖最后由 〇〇 于 2021-9-15 15:12 编辑
〇〇 发表于 2021-9-5 08:33
这是我收集的最快的版本000000010400000000020000000000050604008000300001090000300400200050100000000807 ...

数据
sudoku17.rar (1.19 MB, 下载次数: 2)
7bench1400.7z (368.89 KB, 下载次数: 4)
编译器
https://www.cnblogs.com/nlsoft/p/15079350.html

  1. D:\>cd mingw32\bin

  2. D:\mingw32\bin>gcc \sd.cpp -o \sd.exe -O3

  3. D:\mingw32\bin>cd \

  4. D:\>timer64 sd


  5. Kernel  Time =     0.202 =    5%
  6. User    Time =     3.650 =   93%
  7. Process Time =     3.853 =   99%    Virtual  Memory =      6 MB
  8. Global  Time =     3.890 =  100%    Physical Memory =      3 MB
复制代码


使用道具 举报

回复
论坛徽章:
0
60#
发表于 2021-9-25 00:35 | 只看该作者
I managed to write a similar one using brute force backtracking approach for shortest path tree.  Since other related problems like traveler (go through all points and back to start point) and shopping (go through only selected points and back to entrance or other exits) may probably be solved in the same way without knowledge of other algorithms/theories I will post this one in a new thread.  

使用道具 举报

回复

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

TOP技术积分榜 社区积分榜 徽章 团队 统计 知识索引树 积分竞拍 文本模式 帮助
  ITPUB首页 | ITPUB论坛 | 数据库技术 | 企业信息化 | 开发技术 | 微软技术 | 软件工程与项目管理 | IBM技术园地 | 行业纵向讨论 | IT招聘 | IT文档
  ChinaUnix | ChinaUnix博客 | ChinaUnix论坛
CopyRight 1999-2011 itpub.net All Right Reserved. 北京盛拓优讯信息技术有限公司版权所有 联系我们 未成年人举报专区 
京ICP备16024965号-8  北京市公安局海淀分局网监中心备案编号:11010802021510 广播电视节目制作经营许可证:编号(京)字第1149号
  
快速回复 返回顶部 返回列表