标签:load http long img return size its out turn
1<=n<=200,1<=ai <=1000;
苟题
以下和loj#2541. 「PKUWC2018」猎人杀 一起讲,其中w和a相等
显然可以得出一号存活的概率是
\(\huge \sum_{p \& 1\notin p} \prod_i{\frac{w[pi]}{\sum_{j=i}^{n-1}{wj}+w1}}\)
设W=Πw[pi],Ws=Σwi则可以发现等价于
\(\huge \sum_{p \& 1\notin p} {\frac{W/w1}{\sum_{i=2}^{n}{si}}}\)
可以发现和原式很像,设上面的东西为sum[1],则
\(\huge ans=\sum{\frac{sum[i]*w[i]}{Ws}}\)
于是变成了原问题,原问题及其优美,考虑容斥一个集合S使得S一定在1后死亡
\(\huge sum[1]=\sum{(-1)^{|S|}\frac{w1}{\sum{wj}+w1}}\)
把w的和背包一下即可,可以变成多项式乘起来然后除
时间复杂度O(n^2*A)
#include <bits/stdc++.h>
#define fo(a,b,c) for (a=b; a<=c; a++)
#define fd(a,b,c) for (a=b; a>=c; a--)
#define mod 998244353
#define Mod 998244351
#define ll long long
#define file
using namespace std;
ll f[200001],g[200001],w[200001],ans,Ans,A;
int a[201],n,m,i,j,k,l;
ll qpower(ll a,int b) {ll ans=1; while (b) {if (b&1) ans=ans*a%mod;a=a*a%mod;b>>=1;} return ans;}
int main()
{
freopen("restaurant.in","r",stdin);
#ifdef file
freopen("restaurant.out","w",stdout);
#endif
scanf("%d",&n);m=n*1000;A=1;
fo(i,1,n) scanf("%d",&a[i]),A=A*a[i]%mod;
w[1]=1;
fo(i,2,m) w[i]=mod-w[mod%i]*(mod/i)%mod;
f[0]=1;
fo(i,1,n)
{
fd(j,m,0)
if (f[j])
f[j+a[i]]=(f[j+a[i]]-f[j])%mod;
}
fo(l,1,n)
{
memcpy(g,f,sizeof(f));
fd(i,m,a[l]) g[i-a[l]]=(g[i-a[l]]+g[i])%mod,g[i]=-g[i];
Ans=0;
fo(i,0,m-a[l]) Ans=(Ans+g[i+a[l]]*a[l]%mod*w[i+a[l]])%mod;
ans=(ans+Ans*a[l]%mod*qpower(A,Mod))%mod;
}
printf("%lld\n",(ans+mod)%mod);
fclose(stdin);
fclose(stdout);
return 0;
}
6699. 这钵和餐厅配合的不是很好(restaurant)
标签:load http long img return size its out turn
原文地址:https://www.cnblogs.com/gmh77/p/13062744.html