【[AGC019F] Yes or No】题解

题目链接

题目

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

答案对 \(998244353\) 取模。

思路

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

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

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

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

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

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

所以最后答案为:

\[\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

// 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;
}


posted @ 2021-12-16 18:39  zhangtingxi  阅读(116)  评论(0编辑  收藏  举报