题目传送门

https://lydsy.com/JudgeOnline/problem.php?id=4710

题解

本来想去找一个二项式反演的题的,结果被 https://www.cnblogs.com/GXZlegend/p/11407185.html 骗了,给的最后一道题是一个基础容斥的题。

(不过反演的本质就是容斥呢,如果二项式反演的 \(g(n)\) 的 \(n\) 是 \(0\) 的话也就跟最常见的容斥差不多了)

考虑如果钦定有 \(k\) 个同学没有拿到特产,那么特产中剩下的同学就可以随便分了。对于第 \(i\) 个特产,划分给 \(n-k\) 个同学的方案数显然就是插板法一下就没了,\(\binom {a_i+n-k-1}{n-k-1}\)。

然后容斥上一下就可以了。最后答案就是

\[\sum_{i=0}^n(-1)^i\binom ni \prod_{j=1}^m \binom{a_j+n-i-1}{n-i-1}
\]

#include<bits/stdc++.h>

#define fec(i, x, y) (int i = head[x], y = g[i].to; i; i = g[i].ne, y = g[i].to)
#define dbg(...) fprintf(stderr, __VA_ARGS__)
#define File(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout)
#define fi first
#define se second
#define pb push_back template<typename A, typename B> inline char smax(A &a, const B &b) {return a < b ? a = b , 1 : 0;}
template<typename A, typename B> inline char smin(A &a, const B &b) {return b < a ? a = b , 1 : 0;} typedef long long ll; typedef unsigned long long ull; typedef std::pair<int, int> pii; template<typename I>
inline void read(I &x) {
int f = 0, c;
while (!isdigit(c = getchar())) c == '-' ? f = 1 : 0;
x = c & 15;
while (isdigit(c = getchar())) x = (x << 1) + (x << 3) + (c & 15);
f ? x = -x : 0;
} const int N = 2000 + 7;
const int P = 1e9 + 7; int n, m, mxa;
int a[N]; inline int smod(int x) { return x >= P ? x - P : x; }
inline void sadd(int &x, const int &y) { x += y; x >= P ? x -= P : x; }
inline int fpow(int x, int y) {
int ans = 1;
for (; y; y >>= 1, x = (ll)x * x % P) if (y & 1) ans = (ll)ans * x % P;
return ans;
} int fac[N], inv[N], ifac[N];
inline void ycl(const int &n = ::n) {
fac[0] = 1; for (int i = 1; i <= n; ++i) fac[i] = (ll)fac[i - 1] * i % P;
inv[1] = 1; for (int i = 2; i <= n; ++i) inv[i] = (ll)(P - P / i) * inv[P % i] % P;
ifac[0] = 1; for (int i = 1; i <= n; ++i) ifac[i] = (ll)ifac[i - 1] * inv[i] % P;
}
inline int C(int x, int y) {
if (x < y) return 0;
return (ll)fac[x] * ifac[y] % P * ifac[x - y] % P;
} inline void work() {
ycl(n + mxa);
int ans = 0;
for (int i = 0; i <= n; ++i) {
int f = C(n, i);
if (i & 1) f = P - f;
for (int j = 1; j <= m; ++j) f = (ll)f * C(a[j] + n - i - 1, n - i - 1) % P;
sadd(ans, f);
}
printf("%d\n", ans);
} inline void init() {
read(n), read(m);
for (int i = 1; i <= m; ++i) read(a[i]), smax(mxa, a[i]);
} int main() {
#ifdef hzhkk
freopen("hkk.in", "r", stdin);
#endif
init();
work();
fclose(stdin), fclose(stdout);
return 0;
}

BZOJ4710 [Jsoi2011]分特产 容斥的更多相关文章

  1. BZOJ 4710: [Jsoi2011]分特产(容斥)

    传送门 解题思路 首先所有物品是一定要用完的,那么可以按照物品考虑,就是把每种物品分给\(n\)个人,每个人分得非负整数,可以用隔板法计算.设物品有\(m\)个,方案数为\(C(n+m-1,n-1)\ ...

  2. bzoj4710: [Jsoi2011]分特产 组合+容斥

    4710: [Jsoi2011]分特产 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 289  Solved: 198[Submit][Status] ...

  3. bzoj4710 [Jsoi2011]分特产(容斥)

    4710: [Jsoi2011]分特产 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 814  Solved: 527[Submit][Status] ...

  4. [BZOJ4710][JSOI2011]分特产(组合数+容斥原理)

    4710: [Jsoi2011]分特产 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 395  Solved: 262[Submit][Status] ...

  5. BZOJ4710: [Jsoi2011]分特产【组合数学+容斥】

    Description JYY 带队参加了若干场ACM/ICPC 比赛,带回了许多土特产,要分给实验室的同学们. JYY 想知道,把这些特产分给N 个同学,一共有多少种不同的分法?当然,JYY 不希望 ...

  6. Bzoj4710 [Jsoi2011]分特产

    Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 96  Solved: 62[Submit][Status][Discuss] Description ...

  7. BZOJ4710 JSOI2011分特产(容斥原理+组合数学)

    显然可以容斥去掉每人都不为空的限制.每种物品分配方式独立,各自算一个可重组合乘起来即可. #include<iostream> #include<cstdio> #includ ...

  8. 2019.02.09 bzoj4710: [Jsoi2011]分特产(容斥原理)

    传送门 题意简述:有nnn个人,mmm种物品,给出每种物品的数量aia_iai​,问每个人至少分得一个物品的方案数(n,m,每种物品数≤1000n,m,每种物品数\le1000n,m,每种物品数≤10 ...

  9. bzoj千题计划273:bzoj4710: [Jsoi2011]分特产

    http://www.lydsy.com/JudgeOnline/problem.php?id=4710 答案=总方案数-不合法方案数 f[i][j] 前i种特产分给j个人(可能有人没有分到特产)的总 ...

随机推荐

  1. 微信公众号开发(二)获取access_token

    参考:https://www.cnblogs.com/liuhongfeng/p/4848851.html 一:介绍. 接口调用请求说明 http请求方式: GET https://api.weixi ...

  2. php中substr_compare()区分大小写吗

    PHP substr_compare() 函数 定义和用法 substr_compare() 函数从指定的开始位置比较两个字符串. 提示:该函数是二进制安全且选择性地对大小写敏感(区分大小写). 语法 ...

  3. navigator.userAgent.toLowerCase();判断浏览器做兼容

    js简单实例: var ua = navigator.userAgent.toLowerCase(); if (/android/.test(ua)) { $('.date>div>img ...

  4. (转)运行pip报错:Fatal error in launcher: Unable to create process using '"'

    转:https://blog.csdn.net/cjeric/article/details/73518782 在新环境上安装python的时候又再次遇到了这个情况,这次留意了一下,发现原来的文章有错 ...

  5. P2239螺旋矩阵

    传送 看到这数据范围,显然咱不能暴力直接模拟(二维数组开不下,而且会T掉) 我们目前有两种选择: 1.优化暴力  走这边(jyy tql%%%) 2.数学做法 我们看一下题目中的那个矩阵 我们能不能找 ...

  6. MySql 5.7.20 绿色版安装

    MySql 5.7.20 绿色版安装 一.MySql 安装 1.从官网下载绿色压缩包. 2.解压安装文件到指定目录 3.创建配置文件 my.ini 到解压文件的根目录,my.ini 配置文件如下,需将 ...

  7. C#-概念-类库:类库

    ylbtech-C#-概念-类库:类库 1.返回顶部 1. 类库(Class Library)是一个综合性的面向对象的可重用类型集合,这些类型包括:接口.抽象类和具体类.类库可以解决一系列常见编程任务 ...

  8. Vue.js的列表数据的同步更新方法

    这次给大家带来Vue.js的列表数据的同步更新方法,Vue.js列表数据同步更新方法的注意事项有哪些,下面就是实战案例,一起来看一下. 数组的 push(),pop(),shift(),unshift ...

  9. 【python】 判断纯ascii串

    参考:http://stackoverflow.com/questions/3636928/test-if-a-python-string-is-printable print all(ord(c)& ...

  10. jQuery基础--动画操作

    三组基本动画 <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset=" ...