codeforce AIM tech Round 4 div 2 B rectangles
2017-08-25 15:32:14
writer:pprp
题目:
1 second
256 megabytes
standard input
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:
- All cells in a set have the same color.
- Every two cells in a set share row or column.
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 single integer — the number of non-empty sets from the problem description.
1 1
0
1
2 3
1 0 1
0 1 0
8
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的更多相关文章
- AIM Tech Round 3 (Div. 2)
#include <iostream> using namespace std; ]; int main() { int n, b, d; cin >> n >> ...
- AIM Tech Round 3 (Div. 2) A B C D
虽然打的时候是深夜但是状态比较好 但还是犯了好多错误..加分场愣是打成了降分场 ABC都比较水 一会敲完去看D 很快的就想出了求0和1个数的办法 然后一直wa在第四组..快结束的时候B因为低级错误被h ...
- AIM Tech Round 3 (Div. 2) B
Description Vasya takes part in the orienteering competition. There are n checkpoints located along ...
- 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 ...
- 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 ...
- AIM Tech Round 3 (Div. 2) B 数学+贪心
http://codeforces.com/contest/709 题目大意:给一个一维的坐标轴,上面有n个点,我们刚开始在位置a,问,从a点开始走,走n-1个点所需要的最小路程. 思路:我们知道,如 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- Spark 源码分析 -- RDD
关于RDD, 详细可以参考Spark的论文, 下面看下源码 A Resilient Distributed Dataset (RDD), the basic abstraction in Spark. ...
- WSGI的理解 perfect
https://blog.csdn.net/hzrandd/article/details/10099871 https://blog.csdn.net/cloudxli/article/detail ...
- Python进阶知识
装饰器 迭代器 生成器 mixins 元编程 描述符 量化领域常用 列表推导式 字典推导式 高阶函数 lambda函数 三目表达式
- SpringMVC读取配置文件
源文件 pay.properties: inputCharset=1 receiveUrl=www.baidu.com version=v1.0 language=1 signType=1 merch ...
- JDK动态代理实现源码分析
JDK动态代理实现方式 在Spring框架中经典的AOP就是通过动态代理来实现的,Spring分别采用了JDK的动态代理和Cglib动态代理,本文就来分析一下JDK是如何实现动态代理的. 在分析源码之 ...
- 15.遇到window leaked的解决方法
遇到这个可能是android:configChanges没有配置好 可以试试配置为这个 mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navig ...
- php实现异步的程序调用
浏览器和服务器之间的通信是基于HTTP协议进行链接通讯的,它是一种请求和相应的协议.浏览器通过URL向服务器发送请求,服务器接收到请求并执行请求,然后服务器将执行完成的数据返回到客户端. 这就存在一个 ...
- MySQLdb使用批量插入executemany方法插入mysql
python的MySQLdb库可以使用批量操作executemany,进行多行插入. 比如向user表(username,salt,pwd)插入数据,具体的sql语句如下: sql = 'INSERT ...
- Python第一个爬虫学习
在网上查看大神的关于Python爬虫的文章,代码如下: #coding=utf-8 import urllib import re def getHtml(url): page = urllib.ur ...
- index full scan和index fast full scan区别
触发条件:只需要从索引中就可以取出所需要的结果集,此时就会走索引全扫描 Full Index Scan 按照数据的逻辑顺序读取数据块,会发生单块读事件, Fast Full Index Scan ...