容斥定理,答案就是每个人都分到了每种特产-有人有一种特产没有分到+有人有两种特产没有分到。。。。
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <string>
#define mod 1000000007
#define LL long long
using namespace std;
int c[2005][2005];
int a[2005];
int main()
{
//freopen("ztest.txt","r",stdin);
int n, m;
LL ans = 0;
for (int i=0;i<=2000;++i) c[i][0]=1;
for (int i=1;i<=2000;++i)
for (int j=1;j<=2000;++j)
c[i][j]=(c[i-1][j]+c[i-1][j-1])%mod;
scanf("%d%d", &n, &m);
for(int i = 1; i <= m; i++)
scanf("%d", &a[i]);
for (int i=0, f=1; i<=n; ++i, f=-f)
{
LL now = 1;
for (int j = 1; j <= m; ++j)
now = now * c[a[j]+n-i-1][n-i-1] % mod;
ans = (ans + now * c[n][i] % mod * f) % mod;
}
ans = ( ans % mod + mod) % mod;
printf("%lld\n",ans);
return 0;
}