第一行枚举,用二进制思想,后面的n-1行都可以推出来。边推边验证是否满足要求。
保存最优解
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std;
int a[20][20];
int b[20][20];
int main()
{
int cas,n;
cin>>cas;
for(int ca=1;ca<=cas;ca++)
{
scanf("%d",&n);
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
scanf("%d",&a[i][j]);
int top=(1<<n);
int ans=0x3f3f3f3f;
for(int f=0;f<top;f++)
{
int tmp=f;
int sum=0;
int ok=1;
for(int i=n;i>=1;i--)
{
b[1][i]=(tmp&1);
tmp>>=1;
if(b[1][i]-a[1][i]<0) {ok=0;break;}
if(b[1][i]!=a[1][i]) sum++;
}
if(!ok) continue;
for(int j=1;j<=n;j++)
{
b[2][j]=((b[1][j-1]+b[1][j+1])&1);
if(b[2][j]-a[2][j]<0) {ok=0;break;}
if(a[2][j]!=b[2][j]) sum++;
}
if(!ok) continue;
for(int i=3;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
b[i][j]=((b[i-1][j-1]+b[i-1][j+1]+b[i-2][j])&1);
if(b[i][j]-a[i][j]<0) {ok=0;break;}
if(a[i][j]!=b[i][j]) sum++;
}
}
if(!ok) continue;
for(int i=2;i<=n-1;i++)
{
for(int j=1;j<=n;j++)
{
if(((b[i-1][j]+b[i+1][j]+b[i][j-1]+b[i][j+1])&1)) {ok=0;break;}
}
if(!ok) break;
}
if(!ok) continue;
for(int j=1;j<=n;j++)
{
if((b[n][j-1]+b[n-1][j]+b[n][j+1])&1) {ok=0;break;}
if(b[n][j]-a[n][j]<0) {ok=0;break;}
}
if(!ok) continue;
// for(int i=1;i<=n;i++){
// for(int j=1;j<=n;j++)
// cout<<b[i][j];cout<<endl;}
// cout<<sum<<endl;
ans=min(ans,sum);
}
printf("Case %d: %d\n",ca,ans==0x3f3f3f3f?-1:ans);
}
return 0;
}
分享到:
相关推荐
LDPC译码的详细介绍过程,讲述LDPC译码的分类、各译码的实现过程
宏观行业研究方法MGI-Power-of-Parity_Exec-Summary_CN.pdf
low-density-parity-check(详细介绍译码过程)[汇编].pdf
Galleger的博士论文,LDPC。做了整理
好东西,LDPC方面的内容讲的非常之详细,学习LDPC必备
数组为8位char型数值,通过该函数可以计算出数组的16位循环校验码。
数据通信中误码检测机制的研究,使用MATLAB对二维奇偶校验码进行测试
-e even parity -o odd parity -n no parity (default) -c use clocal mode (no disconnect) -t translate 5 bit codes to ascii -x use software flow (xon/xoff) -r use hardware flow (rts/cts) -f pass ...
Design of Low-density Parity Check codes for MIMO Systems with Doubly-iterative receivers,梅中辉,,A soft interference probabilistic data association (SC-PDA ) detector is proposed for multiple-...
Design of low-density parity-check codes for modulation and detection.pdf
Low Density Parity Check Codes Robert G. Gallager 1963
Digital Design Odd or Even Parity
Improved Low-Density Parity-Check Codes Using Irregular Graphs
Iterative Error Correction Turbo, Low-Density Parity-Check 非常好的一本纠错码教材。
Parity check for decoding QC-LDPC codes with all-diagonal parity-check structure
We present a study of single nanoparticle detection using parity-time (PT) symmetric whispering-gallery mode (WGM) resonators. Our theoretical model and numerical simulations show that, with balanced ...
matlab代码影响上限的MPICH并行实现(多线程和服务器集群)(MacKay提出的总体思路,由Smarandache-Vontobel进行了进一步的开发,由Butler-Siegel改进了),用于QC代码的代码(汉明)距离估计。...
parity-tokio-ipc 这个 crate 抽象了 UNIX/Windows 的进程间传输。 在 UNIX 上,它使用 unix 套接字( tokio_uds crate)和 windows 上的命名管道(实验性的tokio-named-pipes crate)。 端点是传入连接的传输不...
采用异步方式传送数据,偶校验,一位结束位,传输的数据传输速率为9600bit/s。每个数据帧包含10Byte信息,1Byte作为帧起始标志,8Byte数据,1Byte的校验和。 //-----------------------函数声明,变量定义-
令牌注册 Parity UI使用的令牌注册表和BasicCoin ERC20合同。入门该项目使用框架。 要安装所需的依赖项,请运行: yarn install要运行测试套件: yarn test