题意:
分析:
1111
由于 (a[i]) 不降,块的长度只会减小,所以第 (i+1) 层的黑块至多与第 (i) 层的中的一个黑块会有接触,这样有接触之间的黑块连一条边,它们就构成了一个森林。
对于森林,其联通块的个数为:(E(联通块)=点数-边数)
对整个图而言,点数为 (sum_{i=1}^{n}{frac{a[i]}{2}})
对于边数,第 (i) 各环与第 (i+1) 各环之间的有一个黑块相连的概率为:
[frac{frac{2pi}{a[i]}+frac{2pi}{a[i+1]}}{2pi}=frac{1}{a[i]}+frac{1}{a[i+1]}
]
所以,相邻两环之间边的期望为:
[(frac{1}{a[i]}+frac{1}{a[i+1]})*frac{a[i]}{2}*frac{a[i+1]}{2}=frac{a[i]+a[i+1]}{4}
]
总边数的期望为:
[sum_{i=1}^{n-1}{frac{a[i]+a[i+1]}{4}}
]
联通块数量的期望为:
[sum_{i=1}^{n}{frac{a[i]}{2}}-sum_{i=1}^{n-1}{frac{a[i]+a[i+1]}{4}}=frac{a[1]+a[n]}{4}
]
代码:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
int a[12];
ll power(ll a,ll b)
{
ll res=1;
while(b)
{
if(b&1)
res=res*a%mod;
a=a*a%mod;
b>>=1;
}
return res;
}
int main()
{
int t,n;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
ll ans=(a[1]+a[n])*power(4LL,1LL*(mod-2))%mod;
printf("%lld
",ans);
}
return 0;
}
参考:
https://www.cnblogs.com/Lanly/p/13360152.html
https://www.zhihu.com/question/408403255