You are given NXM table. Each cell of the table is colored white or black. Find the number of non-empty sets of cells such that:
All cells in a set have the same color.
Every two cells in a set share row or column.
Input
The "a" of input contains integers n and m (1≤n, m≤50)-the number of rows and the number of columns Correspon dingly.
The next n lines of input contain descriptions of rows. There are m integers, separated by spaces. The number equals 0 if the corresponding cell is colored white and equals 1 if the corresponding cell was colored black.
Outpu
Output single integer-the number of non-empty sets from the problem description.
Example
Input
1 1
0
Output
1
Input
2 3
1 0 1
0 1 0
Output
8
Note
In the second example, there are six one-element. Additionally, there are two two-element sets, the ' one consists ' the ' the ' the ' the ' the ' the ' the ' the ' the ' the ' the ' the E Second one consists of the the the ' the ' and the third cells of the second row. To sum up, there are 8 sets.
Give you a NXM board with 0 or 12 pieces on it. Pieces of the same kind and peers (or columns) can form a set, and a piece can be considered a collection. Ask you how many kinds of collections you can have.
#include <iostream> #include <algorithm> #include <cstdio> #include <cstring> #include <qu
Eue> using namespace std;
typedef long Long LL;
int main () {int m,n;
cin>>n>>m;
int a[51][51];
for (int i=0;i<n;++i) for (int j=0;j<m;++j) {scanf ("%d", &a[i][j]);
int One,zero;
Long Long sum=0;
for (int i=0;i<n;++i) {one=zero=0;
for (int j=0;j<m;++j) if (a[i][j]) one++;
else zero++;
sum+= (1ll<<one)-1;
sum+= (1ll<<zero)-1;
for (int i=0;i<m;++i) {one=zero=0;
for (int j=0;j<n;++j) if (a[j][i]) one++;
else zero++;
sum+= (1ll<<one)-1; sum+= (1ll<<zero)-1;
} cout<<sum-n*m<<endl;
return 0; }
Considering that both N and M are smaller, enumerate 0, 1 pieces of each row, and choose two possibilities for each piece. For example, a row has K 1 pieces, then this line can be formed by the number of sets is 2k−1, minus one because you want to subtract a piece is not selected this illegal state. Columns are the same after enumerating the rows.
After enumerating rows and columns, it is found that only one piece of each collection is enumerated two times, so the final answer is subtracted from the NXM.