BZOJ5091 摘苹果 BZOJ2017年11月月赛 概率,期望

欢迎访问~原文出处——博客园-zhouzhendong

去博客园看该题解


题目传送门 - BZOJ5091 11月月赛B题


题意概括

  


题解


代码

#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;
typedef long long LL;
const int N=100005;
const LL mod=1000000007;
LL LLPow(LL x,LL y){
	if (y==0)
		return 1LL;
	LL xx=LLPow(x,y/2);
	xx=xx*xx%mod;
	if (y&1LL)
		xx=xx*x%mod;
	return xx;
}
LL Inv(LL x){
	return LLPow(x,mod-2);
}
LL n,m,k,d[N],a[N];
int main(){
	memset(d,0,sizeof d);
	scanf("%d%d%d",&n,&m,&k);
	for (int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for (int i=1,a,b;i<=m;i++){
		scanf("%d%d",&a,&b);
		d[a]++,d[b]++;
	}
	LL ans=0;
	for (int i=1;i<=n;i++)
		ans=(ans+d[i]*a[i])%mod;
	printf("%lld",ans*Inv(m*2)%mod*k%mod);
	return 0;
}

  

原文地址:https://www.cnblogs.com/zhouzhendong/p/BZOJ5091.html