ABC350E 题解
题意
有两种操作方式:第一种为把
思路
设
考虑状态转移。若使用第一种操作,则显然有
若使用第二种操作,由于有六种等概率的情况,有
移项得
用以上两种方式中较小的代价转移即可,可以记忆化搜索,使用map记录状态。
代码
#include<iostream>
#include<map>
#define int long long
using namespace std;
int read()
{
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar();}
while(ch>='0'&&ch<='9') { s=s*10+ch-'0'; ch=getchar();}
return s*w;
}
int n,A,X,Y;
map <int,double> f;
map <int,bool> v;
double sol(int x)
{
if(v[x]) return f[x];
v[x]=1;
if(!x) f[x]=0;
else
{
double ta=sol(x/A)+X,tb=Y*1.2;
for(int i=2;i<=6;i++) tb+=sol(x/i)/5;
f[x]=min(ta,tb);
}
return f[x];
}
signed main()
{
n=read(),A=read(),X=read(),Y=read();
printf("%.6lf",sol(n));
return 0;
}