NC229236. Mio visits ACGN Exhibition
描述
输入描述
The first line contains four integers, n, m, p, q(1≤n,m≤500,0≤p,q≤10000).Each of the next n lines contains m space separated integers(0≤≤1), denoting the number in the cell (i,j) of the grid A.
输出描述
Print a single integer, denoting the answer to the question, modulo 998244353.
示例1
输入:
2 2 1 1 0 0 1 1
输出:
2
示例2
输入:
3 3 2 0 0 0 1 0 0 1 1 0 0
输出:
6
C++ 解法, 执行用时: 657ms, 内存消耗: 4396K, 提交时间: 2022-05-20 13:42:17
#include<bits/stdc++.h> #define ll long long using namespace std; const int mod=998244353; int f[2][505][1005]; int main(){ int n,m,p,q,x; cin>>n>>m>>p>>q; f[0][1][0]=1; for(int i=1;i<=n;i++){ int e=i&1; memset(f[e],0,sizeof f[e]); for(int j=1;j<=m;j++){ scanf("%d",&x); for(int k=n+m-1;~k;k--) if(x&&k) f[e][j][k]=(f[e^1][j][k-1]+f[e][j-1][k-1])%mod; else if(!x) f[e][j][k]=(f[e][j-1][k]+f[e^1][j][k])%mod; } } int ans=0; for(int i=q;i<=n+m-1-p;i++) ans=(ans+f[n&1][m][i])%mod; cout<<ans; }