1. 程式人生 > 其它 >【[AGC019F] Yes or No】題解

【[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;
}