这题我们可以把行和列分开来操作 对于所有行来说,我们进行终态枚举,枚举有多少行若只受行的变换作用变成了 1 而后剩下来的变换次数可以用组合用到任意一行上 当然,选中的行具体是什么行也要用组合 对于所有的列同理 而后判断最后1的个数是否为 S <script type="math/tex" id="MathJax-Element-12">S</script>,更新答案即可 代码如下:
#include<bits/stdc++.h> using namespace std; #define P 555555555 int Com[2335][2335]; int getcom(int n,int m){ if(m==0||n==m)return 1; if(Com[n][m])return Com[n][m]; return Com[n][m]=(getcom(n-1,m)+getcom(n-1,m-1))%P; } int main(){ int n,m,Rcnt,Ccnt,s,ans=0; scanf("%d %d %d %d %d",&n,&m,&Rcnt,&Ccnt,&s); int N=min(n,Rcnt),M=min(m,Ccnt); if((N&1)^(Rcnt&1))N--; if((M&1)^(Ccnt&1))M--; for(int i=N;i>=0;i-=2){ int a=(Rcnt-i)/2; for(int j=M;j>=0;j-=2){ int b=(Ccnt-j)/2; if(i*m+j*n-2*i*j==s) ans=(ans+1ll*getcom(n+a-1,n-1)*getcom(m+b-1,m-1)%P*getcom(n,i)%P*getcom(m,j)%P)%P; } } printf("%d\n",ans); return 0; }