Usaco Hamming Codes

Source: Internet
Author: User

The topic is simple, find the n binary length is B, and 22 between the bits at least D bit different

The brute force enumeration is good.

/*id:modengd1prog:hamminglang:c++*/#include <iostream> #include <stdio.h> #include <memory.h> Using namespace Std;int sta[64];bool slove (int sta[64],int n,int b,int d,int deep) {if (deep==n) {bool Isbegi        N=true;                for (int i=0;i<n;i++) {if (isbegin) {cout<<sta[i];            Isbegin=false;            } else cout<< ' <<sta[i];                if ((i%10) ==9)//Every 10 digits of the line {isbegin=true;            cout<<endl;        }} if ((N%10))//check if you need to output line breaks in the last line cout<<endl;    return true;        } for (int i=0;i< (1&LT;&LT;B); i++) {bool allok=true;        Sta[deep]=i;            for (int j=0;j<deep;j++) {int dif=i^sta[j];            int counter=0;                while (dif>0) {dif-=dif&-dif;            counter++; } if (counter<D)//Hamming distance less than D on break {allok=false;            Break    }} if (Allok&&slove (sta,n,b,d,deep+1))//and the Hamming distance of the previously obtained number is sufficient, then enumerate the next return true; } return false;}    int main () {freopen ("hamming.in", "R", stdin);    Freopen ("Hamming.out", "w", stdout);    int n,b,d;    int sta[64];    scanf ("%d%d%d", &n,&b,&d);    Slove (sta,n,b,d,0); return 0;}

  

Usaco Hamming Codes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.