题解
2023-03-07 00:06:32
发布于:上海
73阅读
0回复
0点赞
#include <iostream>
#include <cstring>
using namespace std;
typedef long long ll;
const int MOD = 998244353;
const int N=105, M=2005;
int n, m, a[N][M], hm;
int sum[N], f[N][2*N];
ll ans=1;
void init() {
for(int i=1; i<=n; i++)
for(int j=0; j<=2*n; j++)
f[i][j] = 0;
}
int main() {
cin>>n>>m;
for(int i=1; i<=n; i++) {
sum[i] = 0;
for(int j=1; j<=m; j++) {
cin>>a[i][j];
sum[i] = (sum[i]+1LL*a[i][j])%MOD;
}
ans = (ans * (sum[i]+1))%MOD;
}
for(int c=1; c<=m; c++) {
init();
f[0][n] = 1;
for(int i=1; i<=n; i++)
for(int j=0; j<=2*n; j++) {
ll tmp = f[i-1][j];
if(j>0 && a[i][c])
tmp = (tmp + 1LL * a[i][c] * f[i-1][j-1])%MOD;
int delta = sum[i] - a[i][c];
if(j<2*n && delta)
tmp = (tmp + 1LL * delta *f[i-1][j+1])%MOD;
f[i][j] = tmp;
if(i==n && j>n)
ans = (ans-f[i][j])%MOD;
}
}
cout<<(ans-1+MOD)%MOD<<endl;
return 0;
}
这里空空如也
有帮助,赞一个