NC233875. Ascending Matrix
描述
输入描述
The first line contains integers , and .
输出描述
Print the answer.
示例1
输入:
2 2 2 1 1 1
输出:
5
示例2
输入:
2 2 2 1 2 1
输出:
3
示例3
输入:
4 5 6 2 3 4
输出:
3700125
示例4
输入:
200 100 100 70 60 30
输出:
546626227
C++ 解法, 执行用时: 193ms, 内存消耗: 1860K, 提交时间: 2022-02-21 22:15:51
// author: xay5421 // created: Sat Apr 3 14:44:00 2021 #ifdef xay5421 #define D(...) fprintf(stderr,__VA_ARGS__) #else #define D(...) ((void)0) //#define NDEBUG #endif #include<bits/stdc++.h> #define rep(i,a,b) for(int i=(a);i<=(b);++i) using namespace std; const int P=998244353; int ad(int k1,int k2){return k1+=k2-P,k1+=k1>>31&P;} int su(int k1,int k2){return k1-=k2,k1+=k1>>31&P;} int mu(int k1,int k2){return 1LL*k1*k2%P;} void uad(int&k1,int k2){k1+=k2-P,k1+=k1>>31&P;} void usu(int&k1,int k2){k1-=k2,k1+=k1>>31&P;} template<typename... T>int ad(int k1,T... k2){return ad(k1,ad(k2...));} template<typename... T>void uad(int&k1,T... k2){return uad(k1,ad(k2...));} template<typename... T>void usu(int&k1,T... k2){return usu(k1,ad(k2...));} template<typename... T>int mu(int k1,T... k2){return mu(k1,mu(k2...));} int po(int k1,int k2){ int k3=1; for(;k2;k2>>=1,k1=mu(k1,k1))if(k2&1)k3=mu(k3,k1); return k3; } const int N=100005; int n,m,K,_r,_c,_V,sx[205],sy[205],tx[205],ty[205],a[205][205],w0[205][205],w1[205][205],f[205],fac[N],inv[N],ifac[N]; int C(int k1,int k2){ if(k1<0||k2<0||k1-k2<0)return 0; return 1LL*fac[k1]*ifac[k2]%P*ifac[k1-k2]%P; } int fun(int x,int y){ return C(x+y,x); } int det(){ int res=1; rep(i,1,K){ if(!a[i][i]){ rep(j,i+1,K)if(a[j][i]){res=su(0,res),swap(a[j],a[i]);break;} if(!a[i][i])return 0; } res=mu(res,a[i][i]); rep(j,i+1,K){ int t=mu(a[j][i],po(a[i][i],P-2)); rep(k,i,K)usu(a[j][k],mu(a[i][k],t)); } } return res; } int calc(int V){ int r=_r-1+V-1,c=_c-V+1; rep(i,1,K){ rep(j,1,K){ w0[i][j]=fun(tx[j]-sx[i],ty[j]-sy[i]); for(int _=0;;++_){ int x=r+_,y=c-_; int now=mu(fun(x-sx[i],y-sy[i]),fun(tx[j]-x,ty[j]-y)); usu(w0[i][j],now); if(_)uad(w1[i][j],now); if(x>=tx[j]||y<=sy[i])break; } //D("(%d,%d)=(w0=%d,w1=%d)\n",i,j,w0[i][j],w1[i][j]); } } rep(x,0,K){ rep(i,1,K)rep(j,1,K)a[i][j]=(1LL*w1[i][j]*x+w0[i][j])%P; f[x]=det(); } // [x^{K-V+1}]f rep(i,0,K){ a[i][0]=1; rep(j,1,K){ a[i][j]=mu(a[i][j-1],i); } a[i][K+1]=f[i]; } rep(i,0,K){ assert(a[i][i]); rep(j,0,K)if(i!=j){ int t=mu(a[j][i],po(a[i][i],P-2)); rep(k,0,K+1)usu(a[j][k],mu(a[i][k],t)); } } //rep(i,0,K)D("%d ",mu(a[i][K+1],po(a[i][i],P-2))); int p=K-V+1; return mu(a[p][K+1],po(a[p][p],P-2)); } int main(){ #ifdef xay5421 freopen("a.in","r",stdin); #endif fac[0]=fac[1]=inv[0]=inv[1]=ifac[0]=ifac[1]=1; for(int i=2;i<N;++i)fac[i]=1LL*fac[i-1]*i%P,inv[i]=1LL*(P-P/i)*inv[P%i]%P,ifac[i]=1LL*ifac[i-1]*inv[i]%P; scanf("%d%d%d%d%d%d",&n,&m,&K,&_r,&_c,&_V); if(!--K)puts("1"),exit(0); _c=m-_c+1; rep(i,1,K){ sx[i]=i-1,sy[i]=-(i-1); tx[i]=i-1+n,ty[i]=-(i-1)+m; } printf("%d\n",calc(_V)); return 0; }