这道题呢,我用了一下搜索,还用了一下dp
搜索是40PAC,dp是稳过的
然后呢遇到边缘值我都进行了特殊判断,我感觉这么写好写点
先来看看搜索
#include<bits/stdc++.h>
using namespace std;
int n;
int m;
struct node
{
int now;//现在的位置
int cnt;//次数
};
queue<node> q;//用队列解决bfs
void bfs(int x,int sum)
{
if(sum==m)
{
q.push((node){x,sum});//符合题解,入队
return;
}
if(x==1)//特判1
{
q.push((node){n,sum+1});
q.push((node){2,sum+1});
}
else if(