【期望DP】

【期望DP】

期望

定义:数值x概率的总和

题目积累

Socks 4

https://atcoder.jp/contests/abc412/tasks/abc412_f

题目大意

小红的双排列期望

题目大意

image
(easy)概率失败了没有变化
https://ac.nowcoder.com/acm/contest/112576/F

思路

(1)贪心:越大的概率要给变化越多次的
(2)期望dp:
image

代码

int n;
void solve(){
    cin>>n;
	vector<i64> b(2*n+1,0);
	for(int i=1;i<=2*n;i++) cin>>b[i];
	sort(b.begin()+1,b.end(),cmp64);
	i64 inv100=qmi(100LL,mod-2LL,mod);
	i64 ans=0;
	for(int i=1;i<=2*n;i++){
		i64 tmp=((i64)i+1LL)/2LL;
		i64 invb=qmi(b[i],mod-2LL,mod);
		i64 a=tmp*100LL%mod*invb%mod;
		ans=(ans+a)%mod;
	}
	cout<<ans<<endl;
}
posted @ 2025-07-07 23:59  White_ink  阅读(5)  评论(0)    收藏  举报