Rectangles CodeForces - 844B

You are given n × m table. Each cell of the table is colored white or black. Find the number of non-empty sets of cells such that:

  1. All cells in a set have the same color.
  2. Every two cells in a set share row or column.
Input

The first line of input contains integers n and m (1 ≤ n, m ≤ 50) — the number of rows and the number of columns correspondingly.

The next n lines of input contain descriptions of rows. There are m integers, separated by spaces, in each line. The number equals 0 if the corresponding cell is colored white and equals 1 if the corresponding cell is colored black.

Output

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



暴力法。

先暴力每一行,对于每一行统计有几个白棋x个。每个棋子可选可不选,所以选择白棋的选法有pow(2,x)-1个。黑棋有pow(2,m-x)-1个选法。


同理计算每一列的。

但是我们行和列都有一种情况,那就是只枚举一个棋子作为集合的选法。所以这是重复的,重复了n*m个。所以减去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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值