题解:dp,从最终状态往前推,当当前长度len为奇数时,可以由len+1,len-1转移得到,当len为偶数时,可以由len+1,len-1,len/2转移得到,最后得到dp[0]既是答案
#include<cstdio>
#include<queue>
#include<algorithm>
#include<string.h>
#include<vector>
using namespace std;
const int maxn = 2e7 + 5;
typedef long long LL;
typedef pair<int,LL> PII;
LL d[maxn];
bool vis[maxn];
int main(){
int n;
LL x,y;
scanf("%d%I64d%I64d",&n,&x,&y);
/*
priority_queue<PII,vector<PII>,greater<PII> >q;
q.push(PII(n,0));
*/
queue<int>q;
q.push(n);
memset(d,0x3f,sizeof(d));
LL ans=d[0];
d[n]=0;
while(!q.empty()){
int p=q.front();q.pop();
vis[p]=0;
if(p==0) continue;
int tmp;
if(p%2){
if(p<2*n&&d[p+1]>d[p]+x){
tmp=p+1;
d[tmp]=d[p]+x;
if(!vis[tmp]) q.push(tmp),vis[tmp]=1;
}
if(d[p-1]>d[p]+x){
tmp=p-1;
d[tmp]=d[p]+x;
if(!vis[tmp]) q.push(tmp),vis[tmp]=1;
}
}
else{
if(d[p/2]>d[p]+y){
tmp=p/2;
d[tmp]=d[p]+y;
if(!vis[tmp]) q.push(tmp),vis[tmp]=1;
}
if(p<2*n&&d[p+1]>d[p]+x){
tmp=p+1;
d[tmp]=d[p]+x;
if(!vis[tmp]) q.push(tmp),vis[tmp]=1;
}
if(d[p-1]>d[p]+x){
tmp=p-1;
d[tmp]=d[p]+x;
if(!vis[tmp]) q.push(tmp),vis[tmp]=1;
}
}
}
printf("%I64d\n",d[0]);
return 0;
}