SGU 249.Matrix (Gray code)

Source: Internet
Author: User

Test instructions

Use 0 to 2^ (n+m-1) The number of 2^ (n+m-1) is filled in a 2^n*2^m matrix, so that the binary representation of all adjacent numbers is only one difference.

Solution:

Gray code. For the number of row J of line I, the gray code of I moves left M bit and the Gray code on J is obtained.

#include <cstdio>using namespacestd;intN, m, X;intMain () {scanf ("%d%d",&n,&m);  for(inti =0; I < (1<< N); i++) {         for(intj =0; J < (1<< m); J + +) printf ("%d", (i ^ i >>1) << m | (j ^ J >>1) ); Putchar (Ten); }}
Code

SGU 249.Matrix (Gray code)

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.