bzoj4710 分特产
嘟嘟嘟
因为刚刚做过一道类似的,所以感觉容斥可做。
但自己还是没有搞出来,容斥这方面没做多少题果然是硬伤。
对于每一种特产都用插板法算出分配方案,然后乘起来就是有人可能啥都没得到的方案数,即\(\prod C_{n + a_i + 1} ^ {n - 1}\)。
这时候用容斥,减去至少有一个人什么都没有,加上至少有两个人什么都没有,减去三个人……然后就没了。
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<vector>
#include<stack>
#include<queue>
#include<assert.h>
using namespace std;
#define enter puts("")
#define space putchar(' ')
#define Mem(a, x) memset(a, x, sizeof(a))
#define In inline
typedef long long ll;
typedef double db;
const int INF = 0x3f3f3f3f;
const db eps = 1e-8;
const int maxn = 2e3 + 5;
const ll mod = 1e9 + 7;
In ll read()
{
ll ans = 0;
char ch = getchar(), last = ' ';
while(!isdigit(ch)) last = ch, ch = getchar();
while(isdigit(ch)) ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar();
if(last == '-') ans = -ans;
return ans;
}
In void write(ll x)
{
if(x < 0) x = -x, putchar('-');
if(x >= 10) write(x / 10);
putchar(x % 10 + '0');
}
In void MYFILE()
{
#ifndef mrclr
freopen(".in", "r", stdin);
freopen(".out", "w", stdout);
#endif
}
int n, m, a[maxn];
ll fac[maxn], inv[maxn];
In ll inc(ll a, ll b) {return a + b < mod ? a + b : a + b - mod;}
In ll C(int n, int m) {return fac[n] * inv[m] % mod * inv[n - m] % mod;}
In ll quickpow(ll a, ll b)
{
ll ret = 1;
for(; b; b >>= 1, a = a * a % mod)
if(b & 1) ret = ret * a % mod;
return ret;
}
In void init()
{
fac[0] = inv[0] = 1;
for(int i = 1; i < maxn; ++i) fac[i] = fac[i - 1] * i % mod;
inv[maxn - 1] = quickpow(fac[maxn - 1], mod - 2);
for(int i = maxn - 2; i; --i) inv[i] = inv[i + 1] * (i + 1) % mod;
}
int main()
{
//MYFILE();
n = read(), m = read();
for(int i = 1; i <= m; ++i) a[i] = read();
init();
ll ans = 0;
for(int i = n; i >= 0; --i)
{
ll tp = C(n, n - i);
for(int j = 1; j <= m; ++j) tp = tp * C(i + a[j] - 1, i - 1) % mod;
ans = inc(ans, ((n - i) & 1) ? mod - tp : tp);
}
write(ans), enter;
return 0;
}