4710: [Jsoi2011]分特产
4710: [Jsoi2011]分特产
分析:
容斥原理+隔板法。
代码:
#include<cstdio> #include<algorithm> #include<cstring> #include<iostream> #include<cmath> #include<cctype> #include<set> #include<queue> #include<vector> #include<map> using namespace std; typedef long long LL; inline int read() { int x=0,f=1;char ch=getchar();for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-1; for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';return x*f; } const int N = 2005, mod = 1e9 + 7; int C[N][N], a[N], n, m; int Calc(int x) { int ans = 1; for (int i = 1; i <= m; ++i) ans = 1ll * ans * C[a[i] + x - 1][x - 1] % mod; ans = 1ll * ans * C[n][x] % mod; return ans; } int main() { n = read(), m = read(); for (int i = 1; i <= m; ++i) a[i] = read(); C[0][0] = 1; for (int i = 1; i <= 2000; ++i) { C[i][0] = 1; for (int j = 1; j <= i; ++j) C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mod; } int ans = Calc(n); for (int i = 1; i <= n; ++i) { if (i & 1) ans = (ans - Calc(n - i) + mod) % mod; else ans = (ans + Calc(n - i)) % mod; } cout << (ans + mod) % mod; return 0; }