Submission #20023

# Submission time Handle Problem Language Result Execution time Memory
20023 2016-02-25T08:40:45 Z xdoju 흑백 (kriii4_G) C++14
0 / 100
0 ms 1084 KB
#include <cstdio>
using namespace std;

const int MOD = 1000000007ll;

int modpow(int r, int n) {
	int ret = 1;
	while (n > 0) {
		if (n % 2 > 0) {
			ret = ((long long)ret * r) % MOD;
		}
		r = ((long long)r * r) % MOD;
		n /= 2;
	}
	return ret;
}

inline int modinv(int n) {
	return modpow(n, MOD - 2);
}

inline int modprod(int a, int b) {
	a = a % MOD;
	b = b % MOD;
	return ((long long)a * b) % MOD;
}

inline int modprod(int a, int b, int c) {
	c = c % MOD;
	return (modprod(a, b) * (long long)c) % MOD;
}

inline int moddiv(int a, int b) {
	return ((long long)a * modinv(b)) % MOD;
}

int board[10][10];
int n, m;

bool check(int i, int j, int k, int l, int color) {
	for (int l0 = i; l0 <= j; ++l0) {
		for (int l1 = k; l1 <= l; ++l1) {
			if (board[l0][l1] != color) {
				return false;
			}
		}
	}
	return true;
}

int ans, allCnt;

void rec(int h, int w) {
	if (h == n) {
		++allCnt;
		int bcnt = 0, wcnt = 0;
		for (int i = 0; i < n; ++i) {
			for (int j = i; j < n; ++j) {
				for (int k = 0; k < m; ++k) {
					for (int l = k; l < m; ++l) {
						if (board[i][k] == 0) {
							bcnt += check(i, j, k, l, board[i][k]) ? 1 : 0;
						}
						else {
							wcnt += check(i, j, k, l, board[i][k]) ? 1 : 0;
						}
					}
				}
			}
		}
		ans += bcnt * wcnt;
		return;
	}

	board[h][w] = 0;
	if (w == m - 1) {
		rec(h + 1, 0);
	}
	else {
		rec(h, w + 1);
	}

	board[h][w] = 1;
	if (w == m - 1) {
		rec(h + 1, 0);
	}
	else {
		rec(h, w + 1);
	}


}

void proc() {
	scanf("%d %d", &n, &m);

	ans = 0;
	rec(0, 0);

	ans = moddiv(ans, allCnt);

/*	ans = modprod(ans, modinv(modprod(n, n + 1)));
	ans = modprod(ans, modinv(modprod(m, m + 1)));
	ans = modprod(ans, 4);*/
	printf("%d", ans);
}

int main() {
	proc();
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 1084 KB Output is correct
2 Correct 0 ms 1084 KB Output is correct
3 Incorrect 0 ms 1084 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Halted 0 ms 0 KB -