心跳测试
天使果冻
https://ac.nowcoder.com/acm/contest/11161/A
i<j<n是最关键的,只有满足这个条件才有那个概率公式,不满足这个条件,那么我们默认为概率0
.那么我们就按照1-2-3-4..n的顺序依次入栈即可。
注意需要求一下后缀和
cin要超时要scanf
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6;
typedef long long ll;
ll p=1e9+7;
ll w[maxn];
ll sum[maxn];
ll quick_pow(ll a,ll b)
{
ll res=1;
while(b)
{
if(b&1)
res=res*a%p;
a=a*a%p;
b/=2;
}
return res;
}
ll inv(int x)
{
return quick_pow(x,p-2);
}
int main()
{
ll n;
scanf("%lld",&n);
for(int i=1;i<=n;i++)
{
scanf("%lld",&w[i]);
}
for(int i=n;i>=1;i--)
sum[i]=(sum[i+1]+w[i])%p;
ll ans=1;
for(int i=2;i<=n;i++)
{
ans=ans*w[i]%p;
ans=ans*inv(sum[i])%p;
}
printf("%lld",ans);
return 0;
}
