bryce1010模板

http://acm.hdu.edu.cn/showproblem.php?pid=6314

…………. 又是一个数学题!

这个题使用容斥原理解决的,现场看dls推公式。

我也推了一遍:

f[n][m]=sum { r=0...n,c=0....m }
=C(n,r)*C(m,c)*(-1)^(c+r)*2^((n-r)*(m-c)) 列举至少a行b列的情况
f[n][m]=sum{u=a...n,x=b...m}*sum{v=0...n-u,y=0...m-x}
=C(n,u)*C(m,x)*f[n-u][m-x] 把公式扩展
=C(n,u)*C(m,x)*C(n-u,v)*C(m-x,y)*(-1)^(v+y)*2^((n-u-v)*(m-x-y)) 令w=n-u-v z=m-x-y
上面的式子扩展二项式后:
=n!m!/u!/x!/y!/v!/w!/z!*(-1)^(v+y)*2^(w*z) 多项式归类:
=(-1)^v/u!/v! * (-1)^y/x!/y! *2^(w*z)/w!/z! 编程的时候可以预处理一个pre[s][a] u+v=s;u>=a;表示它的(-1)^v/u!/v!
又u+v=n-w x+y=z-m
=pre[n-w][a]*pre[z-m][b]*2^(w*z)/w!/z!

反正推理过程比较无聊,而且非常耗费时间

#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=998244353;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head const int N=3010;
ll fac[N],fnv[N];
int pw[9000100];
int gg[3010][3010];
ll f[3010][3010];
int n,m,a,b;
int main() {
fac[0]=fnv[0]=1;
rep(i,1,3001) fac[i]=fac[i-1]*i%mod,fnv[i]=powmod(fac[i],mod-2);
pw[0]=1;
for (int i=1;i<=9000000;i++) pw[i]=pw[i-1]*2%mod;
for (int w=0;w<=3000;w++) for (int z=0;z<=3000;z++) gg[w][z]=pw[w*z]*fnv[w]%mod*fnv[z]%mod;
for (int s=0;s<=3001;s++) {
for (int u=s;u>=0;u--) {
int val=fnv[u]*fnv[s-u]%mod;
if ((s-u)%2) val=mod-val;
f[s][u]=(f[s][u+1]+val)%mod;
}
}
while (scanf("%d%d%d%d",&n,&m,&a,&b)!=EOF) {
ll ans=0;
rep(w,0,n-a+1) rep(z,0,m-b+1) ans=(ans+f[n-w][a]*f[m-z][b]%mod*gg[w][z])%mod;
printf("%lld\n",ans*fac[n]%mod*fac[m]%mod);
}
}

hdu6314( 2018 Multi-University Training Contest 2)的更多相关文章

  1. ( 2018 Multi-University Training Contest 2)

    2018 Multi-University Training Contest 2) HDU 6311 Cover HDU 6312 Game HDU 6313 Hack It HDU 6314 Mat ...

  2. HDU4888 Redraw Beautiful Drawings(2014 Multi-University Training Contest 3)

    Redraw Beautiful Drawings Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Jav ...

  3. HDU 5726 GCD (2016 Multi-University Training Contest 1)

      Time Limit: 5000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u Description Give y ...

  4. HDU 4897 Little Devil I(树链剖分)(2014 Multi-University Training Contest 4)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4897 Problem Description There is an old country and ...

  5. HDU 4906 Our happy ending(2014 Multi-University Training Contest 4)

    题意:构造出n个数 这n个数取值范围0-L,这n个数中存在取一些数之和等于k,则这样称为一种方法.给定n,k,L,求方案数. 思路:装压 每位 第1为表示这种方案能不能构成1(1表示能0表示不能)   ...

  6. (2018 Multi-University Training Contest 3)Problem D. Euler Function

    //题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6322 //题目大意:给定 k,求第 k 小的数 n,满足 φ(n) 是合数.显然 φ(1) = 1 ...

  7. hdu6315( 2018 Multi-University Training Contest 2)

    bryce1010模板 http://acm.hdu.edu.cn/showproblem.php?pid=6315 /*hdu 1007 首先我们在建立线段树之前应该思考的是线段树的节点维护一个什么 ...

  8. hdu6313( 2018 Multi-University Training Contest 2)

    bryce1010模板 http://acm.hdu.edu.cn/showproblem.php?pid=6313 参考dls的讲解: 以5*5的矩阵为例: 后一列分别对前一列+0+1+2+3+4操 ...

  9. hdu6311( 2018 Multi-University Training Contest 2)

    bryce1010模板 http://acm.hdu.edu.cn/showproblem.php?pid=6311 从dls思路中,我整理一下自己的思路: 1.首先也是建图 2.建图结束后,一个df ...

随机推荐

  1. mac安装python3

    http://www.jianshu.com/p/51811fa24752 brew install python3 安装路径:/usr/local/Cellar 使用: 执行python3即可 配置 ...

  2. centos 7 / 6 smokeping安装

    官网 值得拥有:http://oss.oetiker.ch/smokeping/doc/reading.en.html 安装依赖包 1 2 yum -y install perl perl-Net-T ...

  3. BestCoder8 1002 Revenge of Nim(hdu 4994) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4994 题目意思:有 n 个 heap(假设从左至右编号为1-n),每个 heap 上有一些 objec ...

  4. codeforces C. Inna and Huge Candy Matrix 解题报告

    题目链接:http://codeforces.com/problemset/problem/400/C 题目意思:给出一个n行m列的矩阵,问经过 x 次clockwise,y 次 horizontal ...

  5. 编译Thrift

    按照 https://syslint.com/blog/tutorial/how-to-install-apache-thrift-on-ubuntu-14-04/ 进行, 编译时出现错误 make[ ...

  6. {{badmatch, {error, eexist}}

    今天在编译cowboy工程在resolve release build时提示编译错误:{{badmatch, {error, eexist}} 后经调查可能是因为rebar的bug导致的,可是删除_b ...

  7. hex2bin

    typedef BYTE unsigned char; </pre><pre code_snippet_id="1639451" snippet_file_nam ...

  8. 内存泄漏分析工具tMemMonitor (TMM)使用简介

    C/C++由于灵活.高效的优点一直以来都是主流的程序设计语言之一,但是其内存的分配与释放均由程序员自己管理,当由于疏忽或错误造成程序未能释放不再使用的内存时就会造成内存泄漏.在大型.复杂的应用程序中, ...

  9. 洛谷P4719 动态DP —— 动态DP(树剖+矩乘)

    题目:https://www.luogu.org/problemnew/show/P4719 感觉这篇博客写得挺好:https://blog.csdn.net/litble/article/detai ...

  10. rsync(六)命令中文手册

    rsync(1) rsync(1) 名称 rsync - 一个快速.多功能的远程(和本地)文件拷贝工具 摘要 Local: rsync [OPTION...] SRC... [DEST] Access ...