English 中文(简体)
通过一切可能的行动进行追踪
原标题:Traversing through all possible moves

奥克·我是处理这个问题的 st。

我有一个阵列物体,其数量为{1,2,3}和代表目标{3,0}的阵列,以及包含两组“一”和“一”的移动功能; j 并将其应用于阵列。

现在,我正试图为此写一个解决者。 因此,我们的想法是,我们将一切可能的价值用于i & j,并在我们达到预期目标之前继续加以应用。

我正试图采用一种宽松的方法来处理这一问题,但我无法理解的是,如何阻止我以不同方式再次入侵,找到使我达到目标的最佳“行动”。

因此,可能采取的行动清单:

(0, 1), (0, 2), (1, 0), (1, 2), (2, 1), (2, 0)

在每次行动之后,我们就有了一个新的“数量阵列”,我们需要将这种行动付诸实施,并检查其中是否有任何行动导致“目标阵列”。

因此,我的假体编码是:

solve(puzzle):
   if puzzle.isSolved: return true;
   else:
        solve(puzzle.move(0, 1));
        solve(puzzle.move(0, 2));
        solve(puzzle.move(1, 0));
        solve(puzzle.move(1, 2));
        solve(puzzle.move(2, 0));
        solve(puzzle.move(2, 1));
  • We are assuming that puzzle.move function returns the puzzle with new state.

现在,我确信,我在这里做了一些令人可怕的错误,但我似乎可以把我的指.放在这里。 因此,任何想法/内容/要点都会受到赞赏。

感谢。

<><>Edit>/strong>

• 每个人都能更清楚地认识到这一点:

自.以来。 在采取这一举动后,我就想制造新的难题,以便重新入侵。 从根本上说,需要的是,在每次流动之后,我们将有新的数量。

因此,在搬迁(i = 0, j = 1)之后,初步数额(a, b, c)的泡沫有一笔款项(a-a, b+a, c)。 我们不采取这种新数量阵列,而是采取下一步行动(i = 0, j = 2)。

但是,这只是“树木”的一部分,还有一条需要加以检查的道路,即当我们申请搬迁时(i = 0, j = 2)最初数额,然后从那里开始。

希望:

b 以前,这个问题被称为水问题(http://www.cut-the-knot.org/ctk/Water.shtml)。

问题回答

我实际上不理解你试图解决的难题,但我不认为问题<>。

存在着令人可怕的错误——你只是在获得积极的解决办法时才停止,但你还需要阻止它永远不退步。

考虑这一法典将采取的一系列步骤:

// Solve puzzle
Is puzzle solved? No.
Move puzzle 0,1
// Solve puzzle
Is puzzle solved? No.
Move puzzle 0,1
// Solve puzzle
Is puzzle solved? No.
Move puzzle 0,1

如果不保证0,1 . 0,1 . 0,1. . 最终解决难题,那么这一算法将永远不会结束。

You either need to

  1. find a way to work out whether a move has "improved" the puzzle,
  2. have some cut-off for when a solution is clearly not working.

你们正在努力使解决(问题)成为休养职能,这样解决,就必须负责确定解决的新论点是什么。 问题在于,如果你通过费解解决,那么就没有办法从先前呼吁中推断一和三分之四的价值观(无情的迷惑不解地储存这些价值观)。 我建议采纳i和j的价值观,然后称之为“pu”。 在要求退约之前,先退约。

solve(puzzle, i, j):
   if solve(puzzle.move(i, j)): return true;
   else:
      j++;
      if (j == i)
         j++;
      if (j > MAX)
         j = 0
         i++;
      if (i > MAX)
         return false;
      solve(puzzle, i, j);

However, I think it is worth noting that any problem that can be solved with recursion can be called without recursion, so let s see what this would like like without it:

i = 0;
j = 1;
solved = false;
while (!solved && i <= MAX)
    while (!solved && j <= MAX)
        solved = puzzle.move(i, j);
        j++;
        if (j == i)
            j++;
        if (j > MAX)
            j = 0
            i++;

在这里,该法典略为简单,它避开了所建议的所有额外呼吁(消耗有限的平线空间)。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...