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. POJ 2485 Highways(最小生成树+ 输出该最小生成树里的最长的边权)

                                                                                                         ...

  2. CSU 1554 SG Value —— 思维

    题目链接:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1554 Description The SG value of a set (mult ...

  3. Kattis - whatdoesthefoxsay —— 字符串

    题目:  Kattis - whatdoesthefoxsay   Determined to discover the ancient mystery—the sound that the fox ...

  4. APP测试走过的那些坑

    我现在的工作有一大部分也是app测试,虽然自己是app开发出身,但是在测试上还是跌入了很多大坑,毕竟二者还是有很大不同,所处的角度也是不一样的.而开发转测试中,我认为较难的也是一个角度的转换,以一个开 ...

  5. 页面渲染——简化paint复杂程度和区域

    Paint是填充像素并且最后合成在用户的屏幕上的过程. 通常是在管道中耗费最大的,你要尽可能的避免使用paint. 动画中使用除了transform和opacity的动画属性都将触发paint pai ...

  6. blog.codedream.ren

    博客将转到 CodeDream  ,新的链接是 http://blog.codedream.ren

  7. 【servlet学习1】使用eclipse+tomcat开发servlet示例

    零.开发环境 1.eclipse+tomcat(tomcat插件已安装到eclipse中). 一.开发servlet步骤 1.在eclipse中新建工程 File —> New —> Ot ...

  8. bzoj 3481 DZY Loves Math III——反演+rho分解质因数

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3481 推推式子发现:令Q=gcd(P,Q),ans=Σ(d|Q) d*phi(P/d).把 ...

  9. HDU2639(01背包第K大)

    Bone Collector II Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  10. 技术胖Flutter第三季-18布局CardWidget 卡片布局组件

    技术胖Flutter第三季-18布局CardWidget 卡片布局组件 博客地址: https://jspang.com/post/flutter3.html#toc-420 最外面是Card布局,里 ...