BZOJ1272: [BeiJingWc2008]Gate Of Babylon
题解:
多重集合的组合数?还是0-m?有些元素有个数限制?
多重集合的组合数可以插板法,0-m直接利用组合数的公式一遍求出来,个数限制注意到只有15个,那我们就暴力容斥了
AC了真舒畅。。
注意开long long
ll n,m,a[],k,p,ans,fac[maxn],inv[maxn];
inline ll c(ll n,ll m)
{
if(n<m)return ;
if(n<p&&m<p)return fac[n]*inv[m]%p*inv[n-m]%p;
return c(n%p,m%p)*c(n/p,m/p)%p;
}
inline void dfs(int x,int w1,ll w2)
{
if(x==k+){ans=(ans+w1*(c(m+n-w2,n)-c(n-w2-,n)))%p;return;}//cout<<n<<' '<<m<<' '<<w2<<' '<<n+m-w2<<' '<<n<<' '<<ans<<endl;return;}
dfs(x+,-w1,w2+a[x]+);
dfs(x+,w1,w2);
} int main() { freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); n=read();k=read();m=read();p=read();
fac[]=;
for1(i,p-)fac[i]=fac[i-]*i%p;
inv[]=inv[]=;
for2(i,,p-)inv[i]=inv[i-p%i]*(p/i+)%p;
for1(i,p-)inv[i]=inv[i]*inv[i-]%p;
for1(i,k)a[i]=read();
dfs(,,);
cout<<(ans+p)%p<<endl; return ; }
1272: [BeiJingWc2008]Gate Of Babylon
Time Limit: 10 Sec Memory Limit: 162 MB
Submit: 195 Solved: 90
[Submit][Status]
Description

Input

Output

Sample Input

Sample Output

HINT
BZOJ1272: [BeiJingWc2008]Gate Of Babylon的更多相关文章
- 【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 ...
- 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 ...
- [BeiJingWc2008]Gate Of Babylon
<基尔伽美修>是人类历史上第一部英雄史诗,两河流域最杰出的文学作品之一.作品讲述了基尔伽美修一生的传奇故事.在动画Fate/staynight中,基尔伽美修与亚瑟王等传说中的英雄人物一起出 ...
- 【BZOJ】【1272】【BeiJingWC2008】Gate of Babylon
组合数学+容斥原理 Orz zyf-zyf 多重集组合数0.0还带个数限制? ——> <组合数学>第6章 6.2带重复的组合 组合数还要模P 0.0? ——> Lucas ...
- Gate Of Babylon bzoj 1272
Gate Of Babylon (1s 128MB) babylon [问题描述] [输入格式] [输出格式] [样例输入] 2 1 10 13 3 [样例输出] 12 [样例说明] [数据范围] 题 ...
- 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件宝具 假设强 ...
随机推荐
- adb shell 出现 error :
首先,确保 adb 服务有起来 adb kill-server adb start-server其次,确保 adb devices 可以找到设备
- C#WinForm中播放背景音乐(亲测可用)
using System.Runtime.InteropServices; public static uint SND_ASYNC = 0x0001; public static uint SND_ ...
- 【转载】错误 CS0016: 未能写入输出文件“c:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/Temporary ASP.NET Files/.........dll”--“拒绝访问。 ”
win7中安装asp.net的问题 编译器错误信息: CS0016: 未能写入输出文件问题解决办法 编译错误 说明: 在编译向该请求提供服务所需资源的过程中出现错误.请检查下列特定错误详细信息并适当地 ...
- 浅谈Feature Scaling
浅谈Feature Scaling 定义:Feature scaling is a method used to standardize the range of independent variab ...
- PHP创建XML文件讲解
<?php #code by coder_apex 2007-6-15 #自动生成一个如下的XML文件 # # <?xml version="1.0& ...
- 安装JDK后JRE与JVM联系浅谈
转自安装JDK后JRE与JVM联系浅谈 安装JDK后JRE.JVM之间的关系是什么呢?那么我们要从安装JDK慢慢说起. 如果安装了JDK,会发同你的电脑有两套JRE: 一套位于 <JDK安装目录 ...
- 使用mysql触发器脚本,解决流水数据的添加。
1.建立表脚本 CREATE DATABASE `spring` DEFAULT CHARACTER SET utf8; USE `spring`; CREATE TABLE `account` ( ...
- Lua 代码编写技巧
1.克隆表 u = {unpack(table)} 一般克隆长度较小的表 2.判断表是否为空 if next(t) == nil then.. 判断该表是否为空,包括t={}的情况 3.插入表 使用 ...
- POJ 3421
X-factor Chains Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5111 Accepted: 1622 D ...
- lintcode :Remove Duplicates from Sorted Array II 删除排序数组中的重复数字 II
题目: 删除排序数组中的重复数字 II 跟进“删除重复数字”: 如果可以允许出现两次重复将如何处理? 样例 给出数组A =[1,1,1,2,2,3],你的函数应该返回长度5,此时A=[1,1,2,2, ...