Rectangles codeforces-844b__ Junior ACM

Source: Internet
Author: User

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. Output

Output single integer-the number of non-empty sets from problem description.



Violence law.

First violence in each row, for each row of statistics there are several white X. Each piece may choose not to choose, therefore chooses the white the choice method to have POW (2,x)-1. Black has POW (2,m-x)-1 options.


Calculate each column in the same vein.

But we have a situation in both rows and columns, which is to enumerate only one piece as a collection of selections. So this is repeated, repeating the n*m. So minus n*m.




#include <cstdio>
#include <iostream>
#include <math.h>
#include <algorithm>
using namespace Std;
int a[100][100];
int n,m;
int main ()
{
cin>>n>>m;
for (int i=0;i<n;i++)
{
for (int j=0;j<m;j++)
{
cin>>a[i][j];
}
}
Long Long ans=0;
for (int i=0;i<n;i++)
{
int geshu=0;
for (int j=0;j<m;j++)
{
if (A[i][j])
{
geshu++;
}
}
Ans=ans+pow (2,geshu) +pow (2,m-geshu)-2;
}
for (int i=0;i<m;i++)
{
int geshu=0;
for (int j=0;j<n;j++)
{
if (A[j][i])
{
geshu++;
}
}
Ans=ans+pow (2,geshu) +pow (2,n-geshu)-2;
}
cout<<ans-n*m<<endl;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.