BZOJ5262(容斥)
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#define N 2000009
using namespace std;
typedef long long ll;
const int maxn=;
vector<ll>vec[N];
ll jie[N],ni[N],ans,k[N],sum[N],n,m,p[N],t,num[N];
const int mod=1e9+;
inline int rd(){
int x=;char c=getchar();bool f=;
while(!isdigit(c)){if(c=='-')f=;c=getchar();}
while(isdigit(c)){x=(x<<)+(x<<)+(c^);c=getchar();}
return f?-x:x;
}
inline ll power(ll x,int y){
ll ans=;
while(y){if(y&)ans=ans*x%mod;x=x*x%mod;y>>=;}
return ans;
}
inline ll C(int x,int y){if(x<y)return ;return jie[x]*ni[y]%mod*ni[x-y]%mod;}
void dfs(int s,int i,int num,int k,int q,ll sum){
if(i>k){
if(s&)ans-=C(sum-num+q-,q-);
else ans+=C(sum-num+q-,q-);
ans=(ans%mod+mod)%mod;
return;
}
dfs(s+,i+,num+p[i]+,k,q,sum);dfs(s,i+,num,k,q,sum);
}
int main(){
// freopen("Equation.in","r",stdin);
// freopen("Equation.out","w",stdout);
n=rd();m=rd();int x,y;
jie[]=;for(int i=;i<=maxn;++i)jie[i]=jie[i-]*i%mod;ni[maxn]=power(jie[maxn],mod-);
for(int i=maxn-;i>=;--i)ni[i]=ni[i+]*(i+)%mod;
for(int i=;i<=m;++i){
k[i]=rd();
for(int j=;j<=k[i];++j)x=rd(),vec[i].push_back(x);sum[i]=rd();
}
t=rd();
memset(num,-,sizeof(num));
for(int i=;i<=t;++i){
x=rd();y=rd();num[x]=y;
}ll Ans=;
for(int i=;i<=m;++i){
int q=;
ans=;
for(int j=;j<k[i];++j)if(~num[vec[i][j]])p[++q]=num[vec[i][j]];
dfs(,,,q,k[i],sum[i]);
(Ans*=ans)%=mod;
}
cout<<Ans;
return ;
}
BZOJ5262(容斥)的更多相关文章
- POJ1091跳蚤(容斥 + 唯一分解 + 快速幂)
题意:规定每次跳的单位 a1, a2, a3 …… , an, M,次数可以为b1, b2, b3 …… bn, bn + 1, 正好表示往左,负号表示往右, 求能否调到左边一位,即 a1* b1 ...
- HDU 4059 容斥初步练习
#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> ...
- HDU 4336 Card Collector (期望DP+状态压缩 或者 状态压缩+容斥)
题意:有N(1<=N<=20)张卡片,每包中含有这些卡片的概率,每包至多一张卡片,可能没有卡片.求需要买多少包才能拿到所以的N张卡片,求次数的期望. 析:期望DP,是很容易看出来的,然后由 ...
- 【BZOJ-4455】小星星 容斥 + 树形DP
4455: [Zjoi2016]小星星 Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 204 Solved: 137[Submit][Status] ...
- cf#305 Mike and Foam(容斥)
C. Mike and Foam time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- UVa12633 Super Rooks on Chessboard(容斥 + FFT)
题目 Source http://acm.hust.edu.cn/vjudge/problem/42145 Description Let’s assume there is a new chess ...
- PE-1 & 暴模|容斥
题意: 求1000以下3或5的倍数之和. SOL: 暴模也是兹瓷的啊... 那么就想到了初赛悲催的滚粗...容斥忘了加上多减的数了... 然后对着题...T = 3*333*(1+333)/2 + 5 ...
- HDU 5838 (状压DP+容斥)
Problem Mountain 题目大意 给定一张n*m的地图,由 . 和 X 组成.要求给每个点一个1~n*m的数字(每个点不同),使得编号为X的点小于其周围的点,编号为.的点至少大于一个其周围的 ...
- hdu 5792(树状数组,容斥) World is Exploding
hdu 5792 要找的无非就是一个上升的仅有两个的序列和一个下降的仅有两个的序列,按照容斥的思想,肯定就是所有的上升的乘以所有的下降的,然后再减去重复的情况. 先用树状数组求出lx[i](在第 i ...
随机推荐
- Jenkins deploy war to tomcat over https
ssl - HTTPS login with Spring Security redirects to HTTP - Stack Overflow https://stackoverflow.com/ ...
- vmware can not be closed virtual machine is busy
VMware does not close when Windows Server 2003 ... |VMware Communities https://communities.vmware.co ...
- asp.net mvc area实现多级controller和多级view
经常需要描述这样的项目结构 ~:. //web根目录├─.admin //管理员功能目录│ └─index.html //管理员目录页面├─.user / ...
- Ubuntu16系统中安装htpasswd
htpasswd是Apache附带的程序, htpasswd生成包含用户名和密码的文本文件, 每行内容格式为“用户名:密码”, 用于用户文件的基本身份认证. 当用户浏览某些网页的时候, 浏览器会提示输 ...
- 通过event记录sql
providers EventServiceProvider.php 添加 protected $listen = [ 'Illuminate\Database\Events\QueryExecute ...
- MySQL 的两个特殊属性 unsigned与 zerofill
1 unsigned unsigned 就是将数字类型无符号化, 例如 int 型的范围:-2^31 ~ 2^31 - 1,而unsigned int的范围:0 ~ 2^32.看起来unsigned ...
- Linux安装jdk环境
前言: 又重新起了一个CentOS7,里面什么都没有,翻出以前CentOS7安装jdk的笔记,现在已经弃用有道云了,用博客比较多,所以把它移过来. 有道云笔记地址(CentOS7安装1.8jdk):h ...
- cordova微信支付回调App闪退
这是cordova版本太高,不兼容这个插件所导致的.解决方案是修改$your_project/plugins/cordova-plugin-wechat/scripts/android-install ...
- Git发生SSL certificate problem: certificate ha错误的解决方法
这两天,不知道为什么,用Git提交代码到服务器时,总出现SSL certificate problem: unable to get local issuer certificate while ac ...
- Linux用户权限指令, 定时任务等指令
一. 网卡配置详解 网络配置文件: /etc/sysconfig/network 网络接口配置文件: /etc/sysconfig/network-scripts/ifcfg-INTERFACE_NA ...