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(广义容斥原理)的更多相关文章

  1. luoguP4491 [HAOI2018]染色 广义容斥原理 + FFT

    非常明显的摆了一个NTT模数.... 题目中求恰好\(k\),那么考虑求至少\(k\) 记\(g(k)\)表示至少\(k\)中颜色出现了恰好\(S\)次 那么,\[g(k) = \binom{M}{k ...

  2. HDU 4920 Matrix multiplication(bitset)

    HDU 4920 Matrix multiplication 题目链接 题意:给定两个矩阵,求这两个矩阵相乘mod 3 思路:没什么好的想法,就把0的位置不考虑.结果就过了.然后看了官方题解,上面是用 ...

  3. HDU 2686 Matrix 3376 Matrix Again(费用流)

    HDU 2686 Matrix 题目链接 3376 Matrix Again 题目链接 题意:这两题是一样的,仅仅是数据范围不一样,都是一个矩阵,从左上角走到右下角在从右下角走到左上角能得到最大价值 ...

  4. HDU - 6314:Matrix (广义容斥)(占位)

    Samwell Tarly is learning to draw a magical matrix to protect himself from the White Walkers. the ma ...

  5. HDU 2204Eddy's爱好(容斥原理)

    Eddy's爱好 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Sta ...

  6. hdu 2686 Matrix 最小费用最大流

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2686 Yifenfei very like play a number game in the n*n ...

  7. hdu 5569 matrix dp

    matrix Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5569 D ...

  8. hdu (欧拉函数+容斥原理) GCD

    题目链接http://acm.hdu.edu.cn/showproblem.php?pid=1695 看了别人的方法才会做 参考博客http://blog.csdn.net/shiren_Bod/ar ...

  9. hdu 2119 Matrix(二分匹配)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2119 Matrix Time Limit: 5000/1000 MS (Java/Others)    ...

随机推荐

  1. 【AGC002E】Candy Piles 博弈论

    题目大意 有\(n\)堆糖果,第\(i\)堆有\(a_i\)个. 两个人轮流决策,决策分为两种: 1.选择糖果数最多的一堆糖果,并把这堆糖全吃了. 2.在每堆非空的糖果堆里拿一颗糖吃掉. 吃掉最后一颗 ...

  2. 【XSY1642】Another Boring Problem 树上莫队

    题目大意 给你一棵\(n\)个点的树,每个点有一个颜色\(c_i\),每次给你\(x,y,k\),求从\(x\)到\(y\)的路径上出现次数第\(k\)多的颜色的出现次数 \(n,q\leq 1000 ...

  3. python_sort(key=) 的使用

    """ sort() 函数内含有 key 可以指定相关的函数来作为排序依据 比如这里指定每一项的索引为1 的元素作为排序依据 默认是以第一个作为排序依据 "&q ...

  4. hiho1259 A Math Problem (数位dp)

    题目链接:http://hihocoder.com/problemset/problem/1259 题目大意:g(t)=(f(i)%k=t)的f(i)的个数 求所有的(0-k-1)的g(i)的异或总值 ...

  5. android Button 属性

    Android中button 继承了TextView组件. 可以这么用: final TextView tv = new Button(getApplicationContext()); tv.set ...

  6. 线段树 by yyb

    线段树 by yyb Type1 维护特殊信息 1.[洛谷1438]无聊的数列 维护一个数列,两种操作 1.给一段区间加上一个等差数列 2.单点询问值 维护等差数列 不难发现,等差数列可以写成\(ad ...

  7. 【CF487E】Tourists(圆方树)

    [CF487E]Tourists(圆方树) 题面 UOJ 题解 首先我们不考虑修改,再来想想这道题目. 我们既然要求的是最小值,那么,在经过一个点双的时候,走的一定是具有较小权值的那一侧. 所以说,我 ...

  8. luogu1196 银河英雄传说 (并查集)

    并查集,不仅记fa,还记与fa的距离,还记根对应的尾节点 路径压缩的时候更新那个距离就行了 #include<bits/stdc++.h> #define pa pair<int,i ...

  9. [SHOI2001]化工厂装箱员(dp?暴力:暴力)

    118号工厂是世界唯一秘密提炼锎的化工厂,由于提炼锎的难度非常高,技术不是十分完善,所以工厂生产的锎成品可能会有3种不同的纯度,A:100%,B:1%,C:0.01%,为了出售方便,必须把不同纯度 ...

  10. 单片机的编程语言和开发环境 LET′S TRY“嵌入式编程”: 3 of 6

    单片机的编程语言和开发环境 LET′S TRY“嵌入式编程”: 3 of 6 本连载讲解作为嵌入式系统开发技术人员所必需具备的基础知识.这些基础知识是硬件和软件技术人员都应该掌握的共通技术知识. 在“ ...