多校day1-可怕

有几种字符串就有几种奇幻排列
组合数+逆元

#include
#include
#include
#include
#define ll long long
using namespace std;
const ll mod=998244353; //质数 
int n,m;
int c[100005];
ll x,y,ans,p[1000005];
ll niyuan(ll x,ll y)
{
    ll q=1;
    while(y>0) 
    {
        if(y%2==1) q=(q*x)%mod; 
        y=y/2;
        x=(x*x)%mod;
    }
    return q;
}   
int main()
{
    freopen("horrible.in","r",stdin);
    freopen("horrible.out","w",stdout); 
    cin>>m;
    for(int i=1;i<=m;i++) 
    {
        scanf("%d",&c[i]);
        n=n+c[i];
    }
    p[0]=1;
    for(int i=1;i<=n;i++) p[i]=(p[i-1]*i)%mod;
    x=n;
    ans=1;
    for(int i=1;i<=m;i++) 
    {
        ll y=(p[c[i]]*p[x-c[i]])%mod;
        ll z=(p[x]*niyuan(y,mod-2))%mod;
        ans=(ans*z)%mod;
        x=x-c[i];
    }
    cout<return 0;
}

你可能感兴趣的:(noip2016训练)