AtCoder Grand Contest 038E - Gachapon

\(\bf Description\)

A \ (0 \) to the \ (n-1 \) random number generator which generates \ (I \) is the probability \ (A_i / S \) , where \ (S = \ sum_ {i = 0} ^ the n-A_i} {\) , you find each number of occurrences \ (\ geq B_i \) of the desired number of times.

\(\bf Solution\)

What pushed burst generating function approach that will not ah ......

min-max-repellent capacity, considering the number of occurrences of each set earliest \ (\ geq B_i \) a desired number of times, a desired additive is that all numbers \ (<B_i \) situation and a desired number of occurrences of .

For one set, the next step out of its probability \ (P = \ FRAC {S} {S} \) , \ (S \) is set \ (A_i \) sum. If we know the probability it appears that \ (p \) times, then there is the expectation that it \ (\ the p-FRAC {} {P} \) .

Then consider \ (p \) how this thing count, if the probability of the number has now generated for \ (t_1 \) to \ (T_m \) , the number is \ (x_1 \) to \ (x_m \) , and set \ (X \) is the sum of the then available (this persimmon still a little confused ah ...... understand, but push yourself is wrong, is autistic)
\ [= the p-the X-! \ prod_ {i = 1} ^ { m} \ left (\ frac { t_i} {s} \ right) ^ {x_i} \ frac {1} {x_i!} = \ frac {X!} {s ^ X} \ prod_ {i = 1} ^ m \ FRAC t_i ^ {} {} {x_i x_i!} \]
\ (F_ {I, J, K} \) representing the forward \ (I \) number, \ (X-J = \) , \ (S = K \) contributions (so-called contribution after contribution of inclusion and exclusion, and only when the count dp \ (\ prod \) that part of the back), and then look like a backpack.

Then I began to write, and then I can not untangle the complexity of the ...... why the recent so old ......

There is a pit is currently the number even if it is 0, and that's not in the set is not the same ...... then I also \ (\ frac {1} { P} \) ended up \ (P \) the ......

Because too lazy, so very gracefully for up to 400 ......

#include<bits/stdc++.h>
#define ll long long
#define fr(i,x,y) for(int i=(x);i<=(y);i++)
#define rf(i,x,y) for(int i=(x);i>=(y);i--)
#define frl(i,x,y) for(int i=(x);i<(y);i++)
using namespace std;
const int N=404;
const int p=998244353;
int n,a[N],b[N];
ll f[N][N];

void read(int &x){ scanf("%d",&x); }

ll qpow(ll sum,ll n){
    ll ans=1;
    for(;n;n>>=1,sum=sum*sum%p) if (n&1) ans=ans*sum%p;
    return ans;
}

ll mul[N],inv[N];
void init(){
    mul[0]=1;
    frl(i,1,N) mul[i]=mul[i-1]*i%p;
    inv[N-1]=qpow(mul[N-1],p-2);
    rf(i,N-2,0) inv[i]=inv[i+1]*(i+1)%p;
}

void Add(ll &x,ll y){
    x+=y;//x%=p;
    if (x<0) x+=p;
    if (x>=p) x-=p;
}

int main(){
    init();
    read(n);
    fr(i,1,n) read(a[i]),read(b[i]);
    int S=0;
    fr(i,1,n) S+=a[i];
    //S=qpow(S,p-2);
    f[0][0]=p-1;
    fr(i,1,n)
     rf(k,400,0)
      fr(j,0,400)
       frl(x,0,b[i])
        if (f[j][k]) Add(f[j+x][k+a[i]],p-f[j][k]*qpow(a[i],x)%p*inv[x]%p);
    ll ans=0;
    fr(j,0,400)
     fr(k,1,400)
      Add(ans,mul[j]*f[j][k]%p*qpow(k,p-1-j)%p*qpow(k,p-2)%p*S%p);
    cout<<ans<<endl;
    return 0;
}

Guess you like

Origin www.cnblogs.com/ymzqwq/p/agc038e.html