令G为一个有向图,其顶点集是1到100的数字集。当j = i + 1或j = 3i时,从顶点i到顶点j会有一条边。 G中从顶点1到顶点100的路径中的最小边数为
(A) 4
(B) 7
(C) 23
(D) 99答案: (B)
说明:任务是找到从顶点1到顶点100的G中路径的最小边数,以便我们可以从顶点i移到i + 1或3i。
Since the task is to minimize number of edges,
we would prefer to follow 3*i.
Let us follow multiple of 3.
1 => 3 => 9 => 27 => 81, now we can't follow multiple
of 3. So we will have to follow i+1. This solution gives
a long path.
What if we begin from end, and we reduce by 1 if
the value is not multiple of 3, else we divide by 3.
100 => 99 => 33 => 11 => 10 => 9 => 3 => 1
So we need total 7 edges.
这个问题的测验