Codeforces AIM Tech Round 4 (Div. 2) B Rectangles(组合数学)

来源:互联网 发布:数据采集平台 编辑:程序博客网 时间:2024/06/07 10:13

很简单的组合数学啊,统计每行每列,去一下重就行,感觉会溢出,等比赛完吧.

/*  xzppp  */#include <iostream>#include <vector>#include <cstdio>#include <string.h>#include <algorithm>#include <queue>#include <map>#include <math.h>#include <string>using namespace std;#define FFF freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define MP make_pair#define PB push_backtypedef long long  LL;typedef unsigned long long ULL;const int MAXN = 50+17;const int MAXM = 20;const int INF = 0x7fffffff;const int MOD = 1e9+7;int main(){    #ifndef ONLINE_JUDGE     FFF    #endif    LL pw[50+17];    pw[0] = 1;    for (int i = 1; i < 50+17; ++i)    {        pw[i] = pw[i-1]*2;    }    int m,n;    cin>>m>>n;    int a[MAXN][MAXN];    for (int i = 0; i < m; ++i)    {        for (int j = 0; j < n; ++j)        {            scanf("%d",&a[i][j]);        }    }    LL ans = 0;    for (int i = 0; i < m; ++i)    {        LL wh = 0,bk = 0;        for (int j = 0; j < n; ++j)        {            if(a[i][j]) wh++;            else bk++;        }        ans += (pw[wh]-1);        ans += (pw[bk]-1);    }    for (int i = 0; i < n; ++i)    {        LL wh = 0,bk = 0;        for (int j = 0; j < m; ++j)        {            if(a[j][i]) wh++;            else bk++;        }        ans += (pw[wh]-1-wh);        ans += (pw[bk]-1-bk);    }    cout<<ans<<endl;    return 0;}
原创粉丝点击