uva 11464 - Even Parity(暴力枚举)

942 篇文章 2 订阅
232 篇文章 0 订阅

题目链接:uva 11464 - Even Parity


题目大意:给出一个由0和1组成的矩阵,修改最少的0变成1,使得矩阵中每个位置的上下左右存在的情况下,和为偶数,无解输出-1。


解题思路:枚举,但是枚举所有位置的话,n最大为15,有2^255,肯定超时。但是不难发现,如果确定了i行,那么i + 1行肯定是确定。所以只要枚举第一行就可以了。


#include <stdio.h>
#include <string.h>

const int N = 20;
const int INF = 0x3f3f3f3f;
const int dir[][2] = { {0, 1}, {0, -1}, {-1, 0} };

int n, ans, v[N][N], s[N][N];

void init() {

	ans = INF;
	memset(v, 0, sizeof(v));
	memset(s, 0, sizeof(s));

	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			scanf("%d", &v[i][j]);
}

int count(int x, int y) {
	int tmp = 0;

	for (int i = 0; i < 3; i++) {
		int p = x + dir[i][0], q = y + dir[i][1];
		if (p < 0 || p >= n) continue;
		if (q < 0 || q >= n) continue;

		tmp += s[p][q];
	}
	return tmp;
}

void solve() {
	int tmp = 0;

	for (int i = 0; i < n; i++)
		if (v[0][i] != s[0][i]) tmp++;

	for (int i = 1; i < n; i++) {
		for (int j = 0; j < n; j++) {
			int k = count(i - 1, j);

			if (k % 2 == 1) {
				s[i][j] = 1;
				if (v[i][j] == 0)	tmp++;
			} else {
				s[i][j] = 0;
				if (v[i][j]) return;
			}
		}
	}

	if (tmp < ans)	ans = tmp;

}

void dfs(int c) {
	if (c == n) {
		solve();
		return;
	}

	s[0][c] = 1;
	dfs(c + 1);

	if ( v[0][c] == 0) {
		s[0][c] = 0;
		dfs(c + 1);
	}
}

int main () {
	int cas;
	scanf("%d", &cas);
	for (int i = 1; i <= cas; i++) {
		init();

		dfs(0);

		printf("Case %d: ", i);
		if (ans == INF) printf("-1\n");
		else printf("%d\n", ans);
	}
	return 0;
}




  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
can achieve near-Shannon limit performance. Can you explain how protograph-based LDPC codes work and what makes them effective in achieving high accuracy? Sure, I'd be happy to explain. LDPC codes are a type of error-correcting code used in digital communication systems to mitigate the effects of noise and interference. Protograph-based LDPC codes are a type of LDPC code that use a protograph matrix to describe the code structure. The protograph matrix specifies the connectivity pattern of the code's check matrix, which is used to detect and correct errors in the transmitted data. The use of protographs allows for the creation of highly structured LDPC codes with a well-defined pattern of connections between nodes. This structure makes it easier to design and analyze the codes, which leads to better performance. Additionally, protograph-based LDPC codes can be optimized for specific transmission scenarios, further improving their performance. The near-Shannon limit performance of protograph-based LDPC codes can be attributed to their ability to correct a high percentage of errors with a low probability of error. This is achieved through the iterative decoding process, where the received data is repeatedly processed through the protograph-based LDPC code until the probability of error is minimized. By carefully constructing the protograph matrix and optimizing the decoding algorithm, protograph-based LDPC codes can achieve extremely high accuracy in noisy communication channels.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值