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) ...
随机推荐
- Yahoo Programming Contest 2019 补题记录(DEF)
D - Ears 题目链接:D - Ears 大意:你在一个\(0-L\)的数轴上行走,从整数格出发,在整数格结束,可以在整数格转弯.每当你经过坐标为\(i-0.5\)的位置时(\(i\)是整数),在 ...
- Django 静态文件相关设置
项目根目录创建 static 文件夹 settings.py 中加入 STATICFILES_DIRS = [ os.path.join(BASE_DIR, "static") ...
- opencv图像融合(大头)
单纯的变大再覆盖上去,头部检测信息不够全,效果实在是太差,就不多说了,只是按照自己的思路玩一玩,没有达到抖音上那么好的效果 import cv2 as cv import numpy as np im ...
- MT【290】内外圆求三角最值
求$\sqrt{\dfrac{5}{4}-\sin x}+2\sqrt{\dfrac{9}{4}+\cos x-\sin x}$的最小值. 提示:$\sqrt{\dfrac{5}{4}-\sin x} ...
- 【HDU - 4342】History repeat itself(数学)
BUPT2017 wintertraining(15) #8C 题意 求第n(n<2^32)个非完全平方数m,以及\(\sum_{i=1}^m{\lfloor\sqrt i\rfloor}\) ...
- python3 集合set
set是一种集合的数据类型,使用{}表示 集合中元素是无序的,并且不可重复,集合最重要的作用就是可以去重 set是不可哈希的,set中的元素必须是可哈希的 可以切片,可以迭代 交集.并集.差集.对称差 ...
- luogu4728 双递增序列 (dp)
设f[i][j]表示以i位置为第一个序列的结尾,第一个序列的长度为j,第二个序列的结尾的最小值 那么对于f[i][j],有转移$f[i+1][j+1]=min\{f[i+1][j+1],f[i][j] ...
- Web Deploy 服务器安装设置与使用
一.服务器的安装设置 1.在windows server上确保IIS安装了[管理服务]这个功能.方法是在[服务器管理器]=>[管理]=>[添加角色和功能]=>[下一步]=>[基 ...
- 2017-12-15python全栈9期第二天第一节之昨日内容回顾
- 信用评分卡 (part 7 of 7)
python信用评分卡(附代码,博主录制) https://study.163.com/course/introduction.htm?courseId=1005214003&utm_camp ...