📜  门|门 IT 2005 |第 56 题

📅  最后修改于: 2021-09-26 03:13:18             🧑  作者: Mango

设 G 是一个有向图,其顶点集是从 1 到 100 的数字集合。当满足 j = i + 1 或 j = 3i 时,从顶点 i 到顶点 j 有一条边。 G 中从顶点 1 到顶点 100 的路径中的最小边数是

(一) 4
(乙) 7
(三) 23
(四) 99答案:(乙)
说明:任务是在 G 中从顶点 1 到顶点 100 的路径中找到最少边数,以便我们可以从顶点 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.

这个问题的测验