2017-08-25 15:32:14

writer:pprp

题目:

B. Rectangles
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

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 的矩阵

让你找到有多少符合要求的集合

比如给你一行, 1001011 你可以选择 一个1两个1三个1四个一, 选择0的情况同理,

所以可以看出来用到了组合数的 C(4,1) + C(4,2) + C(4,3) + C(4,4),

而有如下公式

C(4,0) + C(4,1) + C(4,2) + C(4,3) + C(4,4) =  2 ^ 4

所以公式转化为 2 ^ n - 1(用来计算组合数个个数)

下面的pow函数就是这个功能

之后要横向纵向分别分析,但是这个时候别忘记会重叠,所以减去 n * m

代码如下:

/*
theme: AIM tech Round 4 div 2 B rectangles
writer:pprp
declare:reference from zindow
date:2017/8/25
*/ #include<bits/stdc++.h> using namespace std;
const int maxn = ;
typedef long long ll; //用来计算组合数的
ll pow(int x)
{
ll res = ;
while(x--) res <<= ;
return res-;
} int main()
{
int whi = , bla = ;
int n, m;
ll ans = ;
cin >> n >> m;
int a[maxn][maxn]; for(int i = ; i < n ; i++)
for(int j = ; j < m ; j++)
cin >> a[i][j]; for(int i = ; i < n ; i++)
{
whi = bla = ;
for(int j = ; j < m ; j++)
{
if(a[i][j] == )whi++;
else bla++;
}
ans += pow(whi) + pow(bla);
} // cout << "test" << endl;
// cout << ans << endl; for(int j = ; j < m ; j++)
{
whi = bla = ;
for(int i = ; i < n ; i++)
{
if(a[i][j] == )whi++;
else bla++;
}
// cout << "case :" << j << "whi" << whi << "bla" << bla << endl;
ans += pow(whi) + pow(bla);
} // cout << "test" << endl;
// cout << ans << endl; cout << ans - m*n << endl; return ;
}

横向纵向遍历的时候总是出错,

这样记: 初始化的时候 for(i : 1...n)

            for(j : 1...m)

一般的这种形式是横向遍历,如果要改成纵向遍历,那么就要内外循环翻转过来

i对应n

j对应m

这样就不容易错了

另外补充二维数组的知识点,分析的时候就不容易有问题了

C语言中是按照行优先储存的

codeforce AIM tech Round 4 div 2 B rectangles的更多相关文章

  1. AIM Tech Round 3 (Div. 2)

    #include <iostream> using namespace std; ]; int main() { int n, b, d; cin >> n >> ...

  2. AIM Tech Round 3 (Div. 2) A B C D

    虽然打的时候是深夜但是状态比较好 但还是犯了好多错误..加分场愣是打成了降分场 ABC都比较水 一会敲完去看D 很快的就想出了求0和1个数的办法 然后一直wa在第四组..快结束的时候B因为低级错误被h ...

  3. AIM Tech Round 3 (Div. 2) B

    Description Vasya takes part in the orienteering competition. There are n checkpoints located along ...

  4. AIM Tech Round 3 (Div. 2) A

    Description Kolya is going to make fresh orange juice. He has n oranges of sizes a1, a2, ..., an. Ko ...

  5. AIM Tech Round 3 (Div. 2) (B C D E) (codeforces 709B 709C 709D 709E)

    rating又掉下去了.好不容易蓝了.... A..没读懂题,wa了好几次,明天问队友补上... B. Checkpoints 题意:一条直线上n个点x1,x2...xn,现在在位置a,求要经过任意n ...

  6. AIM Tech Round 3 (Div. 2) B 数学+贪心

    http://codeforces.com/contest/709 题目大意:给一个一维的坐标轴,上面有n个点,我们刚开始在位置a,问,从a点开始走,走n-1个点所需要的最小路程. 思路:我们知道,如 ...

  7. AIM Tech Round 3 (Div. 2)D. Recover the String(贪心+字符串)

    D. Recover the String time limit per test 1 second memory limit per test 256 megabytes input standar ...

  8. AIM Tech Round 4 (Div. 2)ABCD

    A. Diversity time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  9. AIM Tech Round 4 (Div. 2)(A,暴力,B,组合数,C,STL+排序)

    A. Diversity time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...

随机推荐

  1. Flume简介及使用

    一.Flume概述 1)官网地址 http://flume.apache.org/ 2)日志采集工具 Flume是一种分布式,可靠且可用的服务,用于有效地收集,聚合和移动大量日志数据.它具有基于流数据 ...

  2. 【题解】P5151 HKE与他的小朋友

    [题解]P5151 HKE与他的小朋友 实际上,位置的关系可以看做一组递推式,\(f(a_i)=f(a_j),f(a_j)=f(a_t),etc...\)那么我们可以压进一个矩阵里面. 考虑到这个矩阵 ...

  3. Scala函数特性

    通常情况下,函数的參数是传值參数:即參数的值在它被传递给函数之前被确定.可是,假设我们须要编写一个接收參数不希望立即计算.直到调用函数内的表达式才进行真正的计算的函数. 对于这样的情况.Scala提供 ...

  4. django模型:为已存在的表建立模型

    为已经存在的表建立模型:参考https://blog.csdn.net/opera95/article/details/78200024 为已经存在的表建立模型1.python manage.py i ...

  5. (0.2.7)Mysql安装——多实例安装

    (0.2.6)Mysql安装——多实例安装 待完善

  6. 【开发者笔记】java 利用jna调用c#的dll

    一.需求阐述: 如果我们的项目利用c#开发,到了开发后期需要和java组进行合作,其中有一部分业务逻辑利用c#已经code completed,那么我们可能会考虑用java来调用现成的c#dll实现需 ...

  7. 随机深林和GBDT

    随机森林(Random Forest): 随机森林是一个最近比较火的算法,它有很多的优点: 在数据集上表现良好 在当前的很多数据集上,相对其他算法有着很大的优势 它能够处理很高维度(feature很多 ...

  8. memcache服务端与客户端的安装部署

    1)安装memcached前需要先安装libevent [root@aliyun tools]# tar -zxf libevent-1.4.13-stable.tar.gz [root@aliyun ...

  9. springBoot 整合 RabbitMQ 的坑

    1.Consumer raised exception, processing can restart if the connection factory supports it. Exception ...

  10. vue生命周期探究(二)

    vue生命周期探究(二) 转载自:https://segmentfault.com/a/1190000008923105 上一章我们介绍了vue的组件生命周期和路由勾子,这一章,让我们来看看在vue- ...