# Cod sursa(job #2068155)

Utilizator Data 17 noiembrie 2017 11:42:50 Boundingbox 100 cpp done Arhiva de probleme 2.51 kb
``````//#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <climits>
#include <bitset>
#include <cassert>

using namespace std;

const int SIZE = 1 << 10;
int pointer = SIZE;
char buffer[SIZE];

if (pointer == SIZE) {
pointer = 0;
}
return buffer[pointer++];
}

while (!isdigit(ch))
while (isdigit(ch)) {
}
}

const int MAXN = 50;

char a[1 + MAXN][1 + MAXN];
int sum[1 + MAXN + 1][1 + MAXN + 1];
long long power2[1 + MAXN];

long long Gcd(long long a, long long b) {
while (b) {
long long r = a % b;
a = b;
b = r;
}
return a;
}

int main() {
freopen("boundingbox.in", "r", stdin);
freopen("boundingbox.out", "w", stdout);
int tests;
scanf("%d", &tests);
power2[0] = 1;
for (int i = 1; i <= MAXN; i++)
power2[i] = 2 * power2[i - 1];
for (int test = 1; test <= tests; test++) {
int n, m;
scanf("%d%d\n", &n, &m);
for (int i = 1; i <= n; i++) {
scanf("%s\n", a[i] + 1);
for (int j = 1; j <= m; j++)
sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + a[i][j] - '0';
}
long long numerator = 0, denominator = power2[sum[n][m]];
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) {
long long add = power2[sum[n][m]] - 1;
add -= power2[sum[i - 1][m]] - 1;
add -= power2[sum[n][j - 1]] - 1;
add -= power2[sum[n][m] - sum[i][m]] - 1;
add -= power2[sum[n][m] - sum[n][j]] - 1;
add += power2[sum[i - 1][j - 1]] - 1;
add += power2[sum[i - 1][m] - sum[i - 1][j]] - 1;
add += power2[sum[n][j - 1] - sum[i][j - 1]] - 1;
add += power2[sum[n][m] - sum[n][j] - sum[i][m] + sum[i][j]] - 1;