Uva-11464-Even Parity

150 篇文章 0 订阅

这个问将所给m*n的01矩阵,需要求出最少将0变成1的次数,使得所有点的上下左右之和为偶数。有题目的要求可以知道如果对整个地图用DFS的话会超时,而且超时会很严重,而通过观察可以发现后面的几行可以由第一行递推得出。

解法:

首先用DFS枚举第一行的所有情况,然后对每种情况进行递推后面的变化情况,然后取最小即可。

代码:

#include<cstdio>
#include<cstring>
#include<iostream>
#define MAX 16
using namespace std;
const int maxn=1<<16,inf=1<<28;
int n,map[MAX][MAX],vis[maxn],step,ans;
int movex[3]={0,-1,0},movey[4]={1,0,-1};
bool isborder(int x,int y)
{
    if(x<0||x>=n||y<0||y>=n)
	return true;
    return false;
}
void Deal()
{
    int anst=step;
    int imap[MAX][MAX];
    memcpy(imap,map,sizeof(map));
    for(int i=0;i<n-1;i++)
	for(int j=0;j<n;j++)
	{
	    int sum=0;
	    for(int k=0;k<3;k++)
	    {
		int itx=i+movex[k];
		int ity=j+movey[k];
		if(isborder(itx,ity))
		    continue;
		sum+=imap[itx][ity];
	    }
	    if(imap[i+1][j])
	    {
		sum++;
		if(sum&1)
		    return;
	    }
	    else
	    {
		if(sum&1)
		{
		    imap[i+1][j]=1;
		    anst++;
		}
	    }
	}
    for(int j=0;j<n;j++)
    {
	int sum=0;
	for(int k=0;k<3;k++)
	{
	    int itx=n-1+movex[k];
	    int ity=j+movey[k];
	    if(isborder(itx,ity))
		continue;
	    sum+=imap[itx][ity];
	}
	if(sum&1)
	    return;
    }
    ans=min(ans,anst);
}
void DFS(int deep)
{
    if(deep==n)
    {
	Deal();
	return ;
    }
    if(!map[0][deep])
    {
	map[0][deep]=1;
	step++;
	DFS(deep+1);
	step--;
	map[0][deep]=0;
    }
    DFS(deep+1);
}
int main()
{
    int T,cas=1;
    scanf("%d",&T);
    while(T--)
    {
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	    for(int j=0;j<n;j++)
		scanf("%d",&map[i][j]);
	step=0,ans=inf;
	DFS(0);
	if(ans==inf)
	    printf("Case %d: -1\n",cas++);
	else
	    printf("Case %d: %d\n",cas++,ans);
    }
    return 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、付费专栏及课程。

余额充值