[BJWC2008] Gate Of Babylon
容斥+隔板法+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的更多相关文章
- Gate Of Babylon bzoj 1272
Gate Of Babylon (1s 128MB) babylon [问题描述] [输入格式] [输出格式] [样例输入] 2 1 10 13 3 [样例输出] 12 [样例说明] [数据范围] 题 ...
- 【BZOJ】【1272】【BeiJingWC2008】Gate of Babylon
组合数学+容斥原理 Orz zyf-zyf 多重集组合数0.0还带个数限制? ——> <组合数学>第6章 6.2带重复的组合 组合数还要模P 0.0? ——> Lucas ...
- BZOJ1272: [BeiJingWc2008]Gate Of Babylon
题解: 多重集合的组合数?还是0-m?有些元素有个数限制? 多重集合的组合数可以插板法,0-m直接利用组合数的公式一遍求出来,个数限制注意到只有15个,那我们就暴力容斥了 AC了真舒畅.. 注意开lo ...
- 【BZOJ 1272】 1272: [BeiJingWc2008]Gate Of Babylon (容斥原理+卢卡斯定理)
1272: [BeiJingWc2008]Gate Of Babylon Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 254 Solved: 12 ...
- 【BZOJ1272】Gate Of Babylon [Lucas][组合数][逆元]
Gate Of Babylon Time Limit: 10 Sec Memory Limit: 162 MB[Submit][Status][Discuss] Description Input ...
- bzoj1272 Gate Of Babylon(计数方法+Lucas定理+乘法逆元)
Description Input Output Sample Input 2 1 10 13 3 Sample Output 12 Source 看到t很小,想到用容斥原理,推一下发现n种数中选m个 ...
- bzoj1272 Gate Of Babylon
[问题描述] [输入格式] [输出格式] [样例输入] 2 1 10 13 3 [样例输出] 12 [样例说明] [数据范围] 先容斥,考虑枚举哪些条件强制不满足,即直接选出b[i]+1件宝具 假设强 ...
- bzoj 1272: [BeiJingWc2008]Gate Of Babylon
Description Solution 如果没有限制,答案就是 \(\sum_{i=0}^{m}C(n+i-1,i)\) 表示枚举每一次取的个数,且不超过 \(m\),方案数为可重组合 发现这个东西 ...
- ●BZOJ 1272 [BeiJingWc2008]Gate Of Babylon
题链: http://www.lydsy.com/JudgeOnline/problem.php?id=1272 题解: 容斥,Lucas定理本题的容斥考虑类似 [BZOJ 1042 [HAOI200 ...
随机推荐
- 在linux 下配置firewalld
查看firewalld 是否开始与运行 以下两种方式都可以 systemctl status firewalld.service firewall-cmd --state 查看所有打开的端口 以下两种 ...
- poj 3320 jessica's Reading PJroblem 尺取法 -map和set的使用
jessica's Reading PJroblem Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9134 Accep ...
- Unity3D_(API)Random随机数
Unity随机数Random官方文档: 传送门 一.生成一个随机数 二.Random.InitState()生成伪随机数 三.官方文档中常用的方法 创建一个Cube用来挂载Random_Gary.cs ...
- [CSP-S模拟测试]:装饰(状压DP)
题目传送门(内部题114) 输入格式 第一行一个正整数$n$. 接下来一行$n-1$个正整数,第$i$个数为$f_{i+1}$. 接下来一行$n$个数,若第$i$个数为$0$则表示林先森希望$i$号点 ...
- spring-boot 中实现标准 redis 分布式锁
一,前言 redis 现在已经成为系统缓存的必备组件,针对缓存读取更新操作,通常我们希望当缓存过期之后能够只有一个请求去更新缓存,其它请求依然使用旧的数据.这就需要用到锁,因为应用服务多数以集群方式部 ...
- python3笔记五:while语句
一:学习内容 while语句 while-else语句 while语句练习 二:while语句 1. 格式 while 表达式: 语句 2.逻辑 当程序执行到while语句时,首先计算表达式的值 ...
- LeetCode 96. 不同的二叉搜索树(Unique Binary Search Trees )
题目描述 给定一个整数 n,求以 1 ... n 为节点组成的二叉搜索树有多少种? 示例: 输入: 输出: 解释: 给定 n = , 一共有 种不同结构的二叉搜索树: \ / / / \ \ / / ...
- Redis 配置 CONFIG 命令
redis.conf 文件在 安装目录下 CONFIG 命令查看或设置配置项 先登陆 src/redis-cli -a -a 后面是密码,默认为空,没有密码直接登陆 src/redis-cli 1.查 ...
- Kettle使用教程之数据同步
数据模型原型如下: 1.表输入,针对最新的数据输入的表 2.目标表,需要更新的表 3.两个表都需要进行排序操作 4.合并,根据id进行合并 5.数据同步(包括更新.插入.删除) 6.点击运行,就可以实 ...
- CMake下,某些选项的后调整
编译安卓NDK库时,发现在R15的NDK编译出来的库,总是带了-g选项,导致附带调试,文件过大. 搜索一番后,结论是NDK的文件中有问题: https://github.com/android/ndk ...