题目链接

容斥+隔板法+Lucas定理

#include <bits/stdc++.h>
using namespace std;
const int N=1e5+10; int n,m,t,mod,ans;
int fc[N],fv[N],b[15]; int lucas(int n,int m) {
if(m<0||m>n) return 0;
if(n<mod&&m<mod) return 1LL*fc[n]*fv[m]*fv[n-m]%mod;
return 1LL*lucas(n/mod,m/mod)*lucas(n%mod,m%mod)%mod;
} void dfs(int x,int sum,int cnt) {
if(sum>m) return;
if(x>t) {
if(cnt&1) ans=(ans-lucas(m-sum+n,n)+mod)%mod;
else ans=(ans+lucas(m-sum+n,n))%mod;
return;
}
dfs(x+1,sum+b[x]+1,cnt+1);
dfs(x+1,sum,cnt);
} int main() {
scanf("%d%d%d%d",&n,&t,&m,&mod);
fc[0]=fc[1]=fv[0]=fv[1]=1;
for(int i=2; i<mod; ++i) fv[i]=1LL*fv[mod%i]*(mod-mod/i)%mod;
for(int i=2; i<mod; ++i) fv[i]=1LL*fv[i-1]*fv[i]%mod,fc[i]=1LL*fc[i-1]*i%mod;
for(int i=1; i<=t; ++i) scanf("%lld",b+i);
dfs(1,0,0); printf("%lld\n",ans);
return 0;
}

[BJWC2008] Gate Of Babylon的更多相关文章

  1. Gate Of Babylon bzoj 1272

    Gate Of Babylon (1s 128MB) babylon [问题描述] [输入格式] [输出格式] [样例输入] 2 1 10 13 3 [样例输出] 12 [样例说明] [数据范围] 题 ...

  2. 【BZOJ】【1272】【BeiJingWC2008】Gate of Babylon

    组合数学+容斥原理 Orz zyf-zyf 多重集组合数0.0还带个数限制?  ——>  <组合数学>第6章  6.2带重复的组合 组合数还要模P 0.0? ——> Lucas ...

  3. BZOJ1272: [BeiJingWc2008]Gate Of Babylon

    题解: 多重集合的组合数?还是0-m?有些元素有个数限制? 多重集合的组合数可以插板法,0-m直接利用组合数的公式一遍求出来,个数限制注意到只有15个,那我们就暴力容斥了 AC了真舒畅.. 注意开lo ...

  4. 【BZOJ 1272】 1272: [BeiJingWc2008]Gate Of Babylon (容斥原理+卢卡斯定理)

    1272: [BeiJingWc2008]Gate Of Babylon Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 254  Solved: 12 ...

  5. 【BZOJ1272】Gate Of Babylon [Lucas][组合数][逆元]

    Gate Of Babylon Time Limit: 10 Sec  Memory Limit: 162 MB[Submit][Status][Discuss] Description Input ...

  6. bzoj1272 Gate Of Babylon(计数方法+Lucas定理+乘法逆元)

    Description Input Output Sample Input 2 1 10 13 3 Sample Output 12 Source 看到t很小,想到用容斥原理,推一下发现n种数中选m个 ...

  7. bzoj1272 Gate Of Babylon

    [问题描述] [输入格式] [输出格式] [样例输入] 2 1 10 13 3 [样例输出] 12 [样例说明] [数据范围] 先容斥,考虑枚举哪些条件强制不满足,即直接选出b[i]+1件宝具 假设强 ...

  8. bzoj 1272: [BeiJingWc2008]Gate Of Babylon

    Description Solution 如果没有限制,答案就是 \(\sum_{i=0}^{m}C(n+i-1,i)\) 表示枚举每一次取的个数,且不超过 \(m\),方案数为可重组合 发现这个东西 ...

  9. ●BZOJ 1272 [BeiJingWc2008]Gate Of Babylon

    题链: http://www.lydsy.com/JudgeOnline/problem.php?id=1272 题解: 容斥,Lucas定理本题的容斥考虑类似 [BZOJ 1042 [HAOI200 ...

随机推荐

  1. 网页“console”输出图文信息

    http://www.monmonkey.com/javascript/jiben2.html 参考以上链接中的转义字符使用. http://www.cnblogs.com/Wayou/p/chrom ...

  2. CF 672C 两个人捡瓶子 最短路与次短路思想

    C. Recycling Bottles time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  3. textstudio添加中文支持

    修改编译器为XeLaTeX,方法如下: Options -> Configure -> Build -> Default Compiler -> XeLaTeX 并在文本开头处 ...

  4. rm:删除文件或目录

    在使用 rm 命令删除文件或目录时,系统不会产生任何提示信息.此命令的基本格式为:rm[选项] 文件或目录 选项: -f:强制删除(force),和 -i 选项相反,使用 -f,系统将不再询问,而是直 ...

  5. vue2.0中watch总结:普通监听和深度监听

    watch:{} 是一个对象,一定要当成对象来用,可监听数据,是vue中数据发生变化进行处理的函数, 它有三个选项 第一个handler:其值是一个回调函数.即监听到变化时应该执行的函数.第二个是de ...

  6. 作业要求20191010-3 alpha week 1/2 Scrum立会报告+燃尽图 01

    此作业要求参见:https://edu.cnblogs.com/campus/nenu/2019fall/homework/8746 一.小组情况组长:贺敬文组员:彭思雨 王志文 位军营 杨萍队名:胜 ...

  7. LeetCode 96. 不同的二叉搜索树(Unique Binary Search Trees )

    题目描述 给定一个整数 n,求以 1 ... n 为节点组成的二叉搜索树有多少种? 示例: 输入: 输出: 解释: 给定 n = , 一共有 种不同结构的二叉搜索树: \ / / / \ \ / / ...

  8. LeetCode 236. 二叉树的最近公共祖先(Lowest Common Ancestor of a Binary Tree)

    题目描述 给定一棵二叉树, 找到该树中两个指定节点的最近公共祖先. 百度百科中最近公共祖先的定义: “对于有根树T的两个结点u.v,最近公共祖先表示一个结点x,满足x是u.v的祖先且x的深度尽可能大. ...

  9. HTML控件 隐藏

    div的visibility可以控制div的显示和隐藏,但是隐藏后页面显示空白: style="visibility: none;" document.getElementById ...

  10. 自动轮询的recycleView

    import android.content.Context; import android.support.v7.widget.RecyclerView; import android.util.A ...