AT_abc342_f [ABC342F] Black Jack 题解
注意到对方的操作与我们选择的无关。故可以直接 DP 求出对方最终点数为
现在考虑我们怎么做能最优化概率。逆着 DP,
#include <bits/stdc++.h>
using namespace std;
//#define int long long
const int N = 5e5 + 5, MOD = 1e9 + 7, HSMOD = 1610612741, HSMOD2 = 998244353; // Remember to change
int n, l, d;
mt19937 rnd(chrono::system_clock::now().time_since_epoch().count());
long long qpow(long long a, long long b)
{
long long res = 1ll, base = a;
while (b)
{
if (b & 1ll) res = res * base % MOD;
base = base * base % MOD;
b >>= 1ll;
}
return res;
}
bool isprime(int x)
{
if (x == 1) return 0;
for (int i = 2; 1ll * i * i <= x; i++) if (x % i == 0) return 0;
return 1;
}
namespace FastIo
{
#define QUICKCIN ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
int read()
{
char ch = getchar();
int x = 0, f = 1;
while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
while (ch == '-')
{
f = -f;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
{
x = (x << 1) + (x << 3) + (ch ^ 48);
ch = getchar();
}
return x * f;
}
template<class T>
void write(T x)
{
if (x < 0)
{
putchar('-');
x = -x;
}
if (x > 9) write(x / 10);
putchar(x % 10 + '0');
}
template<class T>
void writeln(T x)
{
write(x);
putchar('\n');
}
}
template<typename T>
class Bit
{
public:
T lowbit(T x)
{
return x & -x;
}
T tr[N];
void add(T x, T y)
{
while (x < N)
{
tr[x] += y;
x += lowbit(x);
}
}
T query(T x)
{
T sum = 0;
while (x)
{
sum += tr[x];
x -= lowbit(x);
}
return sum;
}
};
double f[N];
double sum[N];
double f2[N];
double sf[N];
int main()
{
ios::sync_with_stdio(0), cin.tie(nullptr), cout.tie(nullptr);
cin>>n>>l>>d;
f[0]=1;
sum[0]=1;
double avg=1.0/d;
for(int i=1;i<N;i++)
{
if(i<l)
{
int L=max(0,i-d),R=i-1;
f[i]=avg*(sum[R]-(L==0?0:sum[L-1]));
}
else
{
int L=max(0,i-d),R=l-1;
if(L<=R)
{
f[i]=avg*(sum[R]-(L==0?0:sum[L-1]));
}
}
sum[i]=sum[i-1]+f[i];
}
for(int i=0;i<N;i++)
{
if(i<l)
{
f[i]=0;
}
sum[i]=(i?sum[i-1]:0)+f[i];
}
double sumgn=0;
for(int i=n+1;i<N;i++) sumgn+=f[i];
for(int i=n+1;i<N;i++) f2[i]=0;
for(int i=n;i>=0;i--)
{
f2[i]=avg*(sf[i+1]-sf[i+d+1]);
f2[i]=max(f2[i],sumgn+(i?sum[i-1]:0));
sf[i]=sf[i+1]+f2[i];
}
cout<<fixed<<setprecision(15)<<f2[0]<<"\n";
return 0;
}
分类:
题解
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具