本文搬运自本人初中博客园博客,若图片加载不出来,可到原文查看:https://www.cnblogs.com/zhangtingxi/p/15699367.html

题目链接

题目

N+MN+M 个问题,其中有 NN 个问题的答案是 YESMM 个问题的答案是 NO。当你回答一个问题之后,会知道这个问题的答案,求最优策略下期望对多少。

答案对 998244353998244353 取模。

思路

首先假设撇开算期望,就一个贪心,如果 n>mn>m,我们就会不断答yes,然后至少答对 nn 题。

于是总的来说,至少答对 max(n,m)\max(n,m) 题。

假设 n>mn>m,我们每答一次yes,就会到一种 (n1,m)(n-1,m) 的状态,然后必然会达到一种 n=mn=m 的状态。

这个时候,答yes或no的期望都为 0.50.5,然后最后可能会达到 (n1,m)(n-1,m)(n,m1)(n,m-1) 的状态,而这两者本质最后的期望还是一致的。

这个时候我们考虑这一次是否正确。假设错误,没有影响。假设正确,我们相当于“白攒”了 0.50.5 分。

如果考虑在坐标系里走的话理解会方便一些。

所以最后答案为:

max(n,m)+i=1min(n,m)(12×Ci+ii×Cni+miniCm+nm)\max(n,m)+\sum_{i=1}^{\min(n,m)}(\frac{1}{2}\times \frac{C_{i+i}^i\times C_{n-i+m-i}^{n-i}}{C_{m+n}^m})

总结

对于一些题目,如果只有两个抉择的话,我们可以尝试把抽象成一个几何问题,例如经典的走格子问题。

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Problem: AT2705 [AGC019F] Yes or No
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/AT2705
// Memory Limit: 250 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)

#include<bits/stdc++.h>
using namespace std;
#define int long long
inline int read(){int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;
ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<1)+
(x<<3)+(ch^48);ch=getchar();}return x*f;}
#define mo 998244353
//#define N
//#define M
int n, m, i, j, k;
int jc[1000010], ans;

int kuai(int a, int b)
{
int ans=1;
while(b)
{
if(b&1) ans=(ans*a)%mo;
b>>=1;
a=(a*a)%mo;
}
return ans;
}

int C(int m, int n)
{
return jc[m]*kuai(jc[m-n]*jc[n]%mo, mo-2)%mo;
}

signed main()
{
// freopen("tiaoshi.in","r",stdin);
// freopen("tiaoshi.out","w",stdout);
for(i=jc[0]=1; i<=1000000; ++i) jc[i]=jc[i-1]*i%mo;
n=read(); m=read();
ans=max(n, m);
for(i=1; i<=min(n, m); ++i)
ans=(ans+C(i+i, i)*C(n-i+m-i, n-i)%mo*kuai(C(n+m, n), mo-2)%mo*kuai(2, mo-2)%mo)%mo;
printf("%lld", (ans+mo)%mo);
return 0;
}