[题目链接]
https://codeforces.com/contest/486/problem/B
[算法]
显然 , 当Bi,j为0时 , 矩阵A的第i行和第j列所有数均为0
将其它元素填充为1 , 判断是否合法即可
时间复杂度 : O(N^3)
[代码]
#include<bits/stdc++.h> using namespace std; #define MAXN 110 int m , n; int a[MAXN][MAXN],b[MAXN][MAXN]; template <typename T> inline void chkmax(T &x,T y) { x = max(x,y); } template <typename T> inline void chkmin(T &x,T y) { x = min(x,y); } template <typename T> inline void read(T &x) { T f = 1; x = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = -f; for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - '0'; x *= f; } int main() { read(m); read(n); memset(a,255,sizeof(a)); for (int i = 1; i <= m; i++) { for (int j = 1; j <= n; j++) { read(b[i][j]); if (b[i][j] == 0) { for (int k = 1; k <= n; k++) a[i][k] = 0; for (int k = 1; k <= m; k++) a[k][j] = 0; } } } for (int i = 1; i <= m; i++) { for (int j = 1; j <= n; j++) { if (a[i][j] == -1) a[i][j] = 1; } } for (int i = 1; i <= m; i++) { for (int j = 1; j <= n; j++) { int res = 0; for (int k = 1; k <= n; k++) res |= a[i][k]; for (int k = 1; k <= m; k++) res |= a[k][j]; if (res != b[i][j]) { printf("NO "); return 0; } } } printf("YES "); for (int i = 1; i <= m; i++) { for (int j = 1; j < n; j++) { printf("%d ",a[i][j]); } printf("%d ",a[i][n]); } return 0; }