[BZOJ4710][Jsoi2011]分特产 容斥原理

直接容斥一发即可

/**************************************************************
    Problem: 4710
    User: di4CoveRy
    Language: C++
    Result: Accepted
    Time:632 ms
    Memory:34144 kb
****************************************************************/

#include 
#include 
#define mod 1000000007
#define N 2050

using namespace std;
typedef long long LL;
LL C[N][N],F[N],ans;
int n,m;
int a[N];
int main() {
    scanf("%d%d",&n,&m);
    for (int i=1;i<=m;i++) scanf("%d",&a[i]);

    for (int i=0;i<=2000;i++) C[i][i] = C[i][0] = 1LL;
    for (int i=1;i<=2000;i++)
        for (int j=1;j<=i;j++) C[i][j] = C[i-1][j-1] + C[i-1][j] , C[i][j] %= mod;

    for (int i=1;i<=n;i++) F[i] = 1;
    for (int i=1;i<=n;i++)
        for (int j=1;j<=m;j++)
            F[i] *= C[a[j]+i-1][i-1] , F[i] %= mod;
    for (int i=n;i>=0;i--)
        ans += ((i&1) == (n&1)) ? F[i] * C[n][i] % mod : -F[i] * C[n][i] % mod , ans = (ans + mod) % mod;
    printf("%d\n",(int)ans);
    return 0;
}

你可能感兴趣的:(数学,雅礼集训)