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 1
    0
output
  1. 1
input
  1. 2 3
    1 0 1
    0 1 0
output
  1. 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

代码如下:

  1. /*
  2. theme: AIM tech Round 4 div 2 B rectangles
  3. writer:pprp
  4. declare:reference from zindow
  5. date:2017/8/25
  6. */
  7.  
  8. #include<bits/stdc++.h>
  9.  
  10. using namespace std;
  11. const int maxn = ;
  12. typedef long long ll;
  13.  
  14. //用来计算组合数的
  15. ll pow(int x)
  16. {
  17. ll res = ;
  18. while(x--) res <<= ;
  19. return res-;
  20. }
  21.  
  22. int main()
  23. {
  24. int whi = , bla = ;
  25. int n, m;
  26. ll ans = ;
  27. cin >> n >> m;
  28. int a[maxn][maxn];
  29.  
  30. for(int i = ; i < n ; i++)
  31. for(int j = ; j < m ; j++)
  32. cin >> a[i][j];
  33.  
  34. for(int i = ; i < n ; i++)
  35. {
  36. whi = bla = ;
  37. for(int j = ; j < m ; j++)
  38. {
  39. if(a[i][j] == )whi++;
  40. else bla++;
  41. }
  42. ans += pow(whi) + pow(bla);
  43. }
  44.  
  45. // cout << "test" << endl;
  46. // cout << ans << endl;
  47.  
  48. for(int j = ; j < m ; j++)
  49. {
  50. whi = bla = ;
  51. for(int i = ; i < n ; i++)
  52. {
  53. if(a[i][j] == )whi++;
  54. else bla++;
  55. }
  56. // cout << "case :" << j << "whi" << whi << "bla" << bla << endl;
  57. ans += pow(whi) + pow(bla);
  58. }
  59.  
  60. // cout << "test" << endl;
  61. // cout << ans << endl;
  62.  
  63. cout << ans - m*n << endl;
  64.  
  65. return ;
  66. }

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

这样记: 初始化的时候 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. 原!linux 监控 jar定时任务 挂了重启 脚本

    #!/bin/bash time=$(date "+%Y-%m-%d %H:%M:%S") echo "monitor start at: ${time}" P ...

  2. 100个常用的linux命令(转)

    原文:http://blogread.cn/it/article/6368?f=wb 1,echo “aa” > test.txt 和 echo “bb” >> test.txt / ...

  3. maven加载第三方jar包

    <dependency> <groupId>com.yeepay</groupId> <artifactId>yop-sdk</artifactI ...

  4. swagger多个分组代码展示

    /** * api信息 * * @param name 标题 * @param description 描述 * @param version 版本 * @return */ private ApiI ...

  5. finecms万能标签list列表使用方法

    我们在用finecms建站时经常会用到调用文章列表的功能,这时我们可以用万能标签list来实现,当然还可以调用其他一些数据,下面我们就来看看list函数的相关参数和使用方法 action 支持&quo ...

  6. C++入门(1)

    #include<>直接从编译器自带的函数库中寻找文件 #include""是先从自定义的文件中找 ,如果找不到在从函数库中寻找文件 采用"< > ...

  7. http://echarts.baidu.com/demo.html#effectScatter-map

    http://echarts.baidu.com/demo.html#effectScatter-map

  8. Jmeter(八)Jmeter监控tomcat

    1.配置tomcat的配置文件conf/tomcat-users.xml 2. 在“线程组”上右键“添加”--“配置元件”--“HTTP授权管理器”,这里主要是让JMeter能够通过Tomcat的基本 ...

  9. linux 目录与文件命令

    目录与文件常用命令 1.cd命令 cd [相对路径或绝对路径或特殊符号] 功用:变换目录 ps: 不加参数时,默认切换到用户主目录,即环境变量HOME指定的目录,如root用户的HOME变量为/roo ...

  10. PAT 1125 Chain the Ropes[一般]

    1125 Chain the Ropes (25 分) Given some segments of rope, you are supposed to chain them into one rop ...