HLG 1253 Count the Number of Cycles【ldpc环】

Description
 In information theory, a low-density parity-check (LDPC) code is a linear error correcting code, a method of transmitting a message over a noisy transmission channel, and is constructed using a sparse bipartite graph. LDPC codes are capacity-approaching codes, which means that practical constructions exist that allow the noise threshold to be set very close (or even arbitrarily close on the BEC) to the theoretical maximum (the Shannon limit) for a symmetric memory-less channel.
LDPC codes are defined by a sparse parity-check matrix. This parity-check matrix is often randomly generated and the elements in it are 0 or 1. If we want use LDPC codes, we should make the parity-check matrix have no cycles. When four vertices of the rectangle in the matrix are 1, we say that the matrix has one cycle. Now we want to know how many cycles are in the matrix.
For a given matrix, you are to count the number of cycles in the matrix.
Input
 There are several test cases, each test case starts with a line containing two positive integers M and N. M and N is the size of the matrix (1 <= M <= 100, 1 <= N <= 100). Next follow a matrix which contains only number 0 and 1. The input will finish with the end of file.
Output
 For each the case, your program will output the number of cycles in the given matrix on separate line.
Sample Input
1 31 1 12 31 0 10 1 13 31 0 10 1 11 1 1
Sample Output
002
方法:暴力枚举

code:

View Code
#include<stdio.h>
int a[101][101];
int main()
{
int n,m,tot,s,i,j,k;
while(scanf("%d%d",&n,&m)!=EOF)
{
for(i=0;i<n;i++)
for(j=0;j<m;j++)
scanf("%d",&a[i][j]);
for(i=tot=s=0;i<n-1;i++)
for(j=i+1;j<n;j++)
{
for(k=0;k<m;k++)
s+=a[i][k]*a[j][k];
if(s>=2)
tot+=s*(s-1)/2;
s=0;
}
printf("%d\n",tot);
}
return 0;
}

 

转载于:https://www.cnblogs.com/dream-wind/archive/2012/03/16/2400028.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值