HDU - 6314 Matrix(广义容斥原理)
http://acm.hdu.edu.cn/showproblem.php?pid=6314
题意
对于n*m的方格,每个格子只能涂两种颜色,问至少有A列和B行都为黑色的方案数是多少。
分析
参考https://blog.csdn.net/IcePrincess_1968/article/details/81255138
重点在于计算容斥系数。
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <ctime>
#include <vector>
#include <queue>
#include <map>
#include <stack>
#include <set>
#include <bitset>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ms(a, b) memset(a, b, sizeof(a))
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define eps 0.0000000001
#define IOS ios::sync_with_stdio(0);cin.tie(0);
#define random(a, b) rand()*rand()%(b-a+1)+a
#define pi acos(-1)
const ll INF = 0x3f3f3f3f3f3f3f3fll;
const int inf = 0x3f3f3f3f;
const int maxn = + ;
const int maxm = + ;
const int mod = ; int c[maxn][maxn],pw[maxn*maxn],fa[maxn],fb[maxn]; inline int add(int x){
if(x>=mod) x-=mod;
return x;
}
inline int sub(int x){
if(x<) x+=mod;
return x;
}
inline void init() {
c[][]=;
for(int i=;i<maxn;i++){
c[i][]=c[i][i]=;
for(int j=;j<i;j++) c[i][j]=add(c[i-][j]+c[i-][j-]);
}
pw[]=;
for(int i=;i<maxn*maxn;i++){
pw[i]=add(pw[i-]+pw[i-]);
}
} int main() {
#ifdef LOCAL
freopen("in.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
int n,m,A,B;
init();
while(~scanf("%d%d%d%d",&n,&m,&A,&B)){
fa[A]=;
for(int i=A+;i<=n;i++){
fa[i]=;
for(int j=A;j<i;j++){
fa[i]=sub(fa[i]-1ll*c[i-][j-]*fa[j]%mod);
}
}
fb[B]=;
for(int i=B+;i<=m;i++){
fb[i]=;
for(int j=B;j<i;j++){
fb[i]=sub(fb[i]-1ll*c[i-][j-]*fb[j]%mod);
}
}
int ans=;
for(int i=A;i<=n;i++){
for(int j=B;j<=m;j++){
ans=add(ans+1ll*fa[i]*fb[j]%mod*c[n][i]%mod*c[m][j]%mod*pw[(n-i)*(m-j)]%mod);
}
}
printf("%d\n",ans);
}
return ;
}
HDU - 6314 Matrix(广义容斥原理)的更多相关文章
- luoguP4491 [HAOI2018]染色 广义容斥原理 + FFT
非常明显的摆了一个NTT模数.... 题目中求恰好\(k\),那么考虑求至少\(k\) 记\(g(k)\)表示至少\(k\)中颜色出现了恰好\(S\)次 那么,\[g(k) = \binom{M}{k ...
- HDU 4920 Matrix multiplication(bitset)
HDU 4920 Matrix multiplication 题目链接 题意:给定两个矩阵,求这两个矩阵相乘mod 3 思路:没什么好的想法,就把0的位置不考虑.结果就过了.然后看了官方题解,上面是用 ...
- HDU 2686 Matrix 3376 Matrix Again(费用流)
HDU 2686 Matrix 题目链接 3376 Matrix Again 题目链接 题意:这两题是一样的,仅仅是数据范围不一样,都是一个矩阵,从左上角走到右下角在从右下角走到左上角能得到最大价值 ...
- HDU - 6314:Matrix (广义容斥)(占位)
Samwell Tarly is learning to draw a magical matrix to protect himself from the White Walkers. the ma ...
- HDU 2204Eddy's爱好(容斥原理)
Eddy's爱好 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Sta ...
- hdu 2686 Matrix 最小费用最大流
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2686 Yifenfei very like play a number game in the n*n ...
- hdu 5569 matrix dp
matrix Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5569 D ...
- hdu (欧拉函数+容斥原理) GCD
题目链接http://acm.hdu.edu.cn/showproblem.php?pid=1695 看了别人的方法才会做 参考博客http://blog.csdn.net/shiren_Bod/ar ...
- hdu 2119 Matrix(二分匹配)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2119 Matrix Time Limit: 5000/1000 MS (Java/Others) ...
随机推荐
- Nginx 添加 PHP 支持
背景介绍默认安装的Nginx是无法打开php文件的,需要修改相关配置才能支持php 安装yum -y install epel-release yum -y install nginx yum ins ...
- JLOI2016 简要题解
「JLOI2016」侦查守卫 题意 有一个 \(n\) 个点的树,有 \(m\) 个关键点需要被监视.可以在其中一些点上插眼,在 \(i\) 号点上放眼需要花费 \(w_i\) 的代价,可以监视距离 ...
- Hdoj 1374.Knight Moves 题解
Problem Description A friend of you is doing research on the Traveling Knight Problem (TKP) where yo ...
- 【Luogu4916】魔力环(Burnside引理,组合计数)
考虑\(Burside\)引理,设\(f(x)\)表示置换拆成循环的个数为\(x\)时的答案,那么最终的结果就是\(\displaystyle \frac{\sum_{i=1}^n f(gcd(i,n ...
- js多回调函数
多回调问题 前端编程时,大多通过接口交换数据,接口调用都是异步的,处理数据都是在回调函数里. 假如需要为一个用户建立档案,需要准备以下数据,然后调用建档接口 name // 用户名字 使用接口 ...
- JS简易弹出层
目标 实现简易的js弹出框.为了简单灵活的在小项目中使用. 实现思路 研究bootstrap的弹出框效果后,认为层级示意图如下: 层说明 弹出层分为三层.最底层的遮罩层,覆盖在浏览器视口上.它之上是弹 ...
- LOJ#6283. 数列分块入门 7
对于每个区间先乘在加,如果我修改的是部分的块,我就需要把现这个块的add和mul标记全部放下去,然后再更新. #include<map> #include<set> #incl ...
- 状压DP总结
状态压缩就是将一行的状态压成一个二进制数,这个数的二进制形式反映了这一行的情况 比如0100111的意义为:这一排的第一个数没被使用,第二个被占用了,第三四个没被占用,第五六七个被占用 我们知道位运算 ...
- LaTex in Markdown
上次写了Markdown,这次用到了LaTex,也出一期(吐槽,工作量比Markdown高太多...) Markdown基础:https://www.cnblogs.com/dotnetcrazy ...
- nodejs的某些api~(六)HTTPS
node的HTTPS模块接口与HTTP其实差不多,就是多了一个认证证书,私钥的配置等等,API都相似的. 在客户端服务器通信的方法中,只有HTTPS是最安全的,它的原理是客户端和服务器发送自己的公钥, ...