Codeforces 844B
来源:互联网 发布:音乐剪辑合成软件 编辑:程序博客网 时间:2024/06/18 17:17
链接:
http://codeforces.com/contest/844/problem/B
题目:
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:
All cells in a set have the same color.
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.
Examples
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 sets. Additionally, there are two two-element sets, the first one consists of the first and the third cells of the first row, the second one consists of the first and the third cells of the second row. To sum up, there are 8 sets.
题意:
给你一个
思路:
考虑到n和m都比较小,分别枚举每一行的0、1棋子,对于每个棋子有选和不选两种可能。比如说某一行有k个1棋子,那么这一行可以形成的集合的数目就是
枚举完行和列之后会发现每个集合只有一个一个棋子的情况都被枚举了两遍,所以最终答案再减去
实现:
#include <iostream>#include <algorithm>#include <set>#include <string>#include <vector>#include <queue>#include <map>#include <stack>#include <list>#include <iomanip>#include <functional>#include <sstream>#include <cstdio>#include <cstring>#include <cmath>#include <cctype>#define edl putchar('\n')#define ll long long#define clr(a,b) memset(a,b,sizeof a)#define rep(i,m,n) for(int i=m ; i<=n ; i++)inline int read_() {int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9') {if(ch=='-')f=-1; ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f; }namespace FastIO { const int SIZE = 1 << 16; char buf[SIZE], obuf[SIZE], str[60]; int bi = SIZE, bn = SIZE, opt; int read(char *s) { while (bn) {for (; bi < bn && buf[bi] <= ' '; bi++);if (bi < bn) break; bn = fread(buf, 1, SIZE, stdin);bi = 0;}int sn = 0;while (bn) { for (; bi < bn && buf[bi] > ' '; bi++) s[sn++] = buf[bi];if (bi < bn) break; bn = fread(buf, 1, SIZE, stdin);bi = 0;}s[sn] = 0;return sn;} bool read(int& x) {int n = read(str), bf;if (!n) return 0; int i = 0; if (str[i] == '-') bf = -1, i++; else bf = 1; for (x = 0; i < n; i++) x = x * 10 + str[i] - '0';if (bf < 0) x = -x;return 1;}};#define read(x) FastIO::read(x)#define read2(x,y) read(x),read(y)#define read3(x,y,z) read(x),read(y),read(z)#define readin read_()using namespace std;const int maxn = 57, mod = int(1e9)+7;int mp[maxn][maxn];int main() {#ifndef ONLINE_JUDGE freopen("in.txt","r",stdin); printf("init! init! init!\n");#endif int n, m, cnt1, cnt0; read2(n, m); ll ans = 0; rep(i,1,n) rep(j,1,m) read(mp[i][j]); rep(i,1,n) { cnt0 = cnt1 = 0; rep(j,1,m) mp[i][j] ? cnt1++ : cnt0++; ans += (1ll<<cnt0)-1, ans += (1ll<<cnt1)-1; } rep(i,1,m) { cnt0 = cnt1 = 0; rep(j,1,n) mp[j][i] ? cnt1++ : cnt0++; ans += (1ll<<cnt0)-1, ans += (1ll<<cnt1)-1; } printf("%lld\n", ans-n*m); return 0;}
- Codeforces 844 B Rectangles
- Codeforces 844B
- Codeforces 844B Rectangles
- codeforces B
- codeforces B
- codeforces B
- codeforces B
- CodeForces 626B CodeForces 626B【暴力】
- CodeForces 841B (B) 博弈
- codeforces 134B
- codeforces#98 b
- codeforces 105 div2 B
- Codeforces 166B - Polygons
- codeforces B. Coins
- codeforces----193B Xor
- codeforces----208B Solitaire
- Codeforces 1B - Spreadsheet
- codeforces 214B Hometask
- Codeforces Round #426 (Div. 2) A B C D E
- 省市(中国大学)二级联动的精髓写法
- Oracle中用户和模式的区别
- DOM(文档对象模型)--1获取节点、节点的增删改
- 算法之 求最小最大数
- Codeforces 844B
- JavaWeb: Cookie,EL表达式,标准标签库
- Emmet缩写语法
- 662. Maximum Width of Binary Tree
- 状态机的C语言编程
- mac 远程访问window
- ThinkPHP的学习
- python的retrying模块
- Spring简介