Files
python/TangDou/LanQiaoBei/LanQiaoBei13GuoSai/3.md
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

50 lines
1.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

### 题目分析
* 一共$n$个木桩,青蛙现在在第$1$个木桩上。
* 每个木桩上面有一个数字,表示从此木桩出发,最远可以跳几个木桩。比如有数字$2$,表示一次最远可以跳$2$个木桩。
* 从$1$号木桩出发,跳到$n$号木桩上,问**最少**需要几步?
$$\large [2,1,5,1,3]$$
* 不能只看眼前,不看将来,不是本次跳的越远越好,挑最远的跳,可能就略过了**以后更有利**的木桩。
<br>
* 从当前木桩($x$)出发,可以有几种选择呢?$1<=?<=x$种选择。
<br>
* **可不可以向后跳呢**?
* 可能需要一个状态记录的数组$st$,装$st[3]=1$
* 最短路径采用广度优先遍历$bfs$
---
(1)输入$n$,$N=110$,$a[N]$
(2) int st[N];
(3)
```c++
queue<PII> q;
//初始化,老大入队列
//老大已使用过
while(q.size()){
auto t=q.front();
q.pop();
if(目标位置是终点){
输出t.second
break;
}
从1到当前木桩上的数字进行遍历
{
for (从 1 到 t.first+1) {
下一个位置 x = t.first + i;
如果x走过了 continue;
//填充到队列中,做为下一跳的起点
q.push({x, 当前步数 + 1});
标识x已使用过
}
}
}
```