gray code 格雷码 递归
格雷码
the n-1 bit code, with 0 prepended to each word, followd by the n-1 bit code in reverse order,
with 1 prepended to each word.
public class GrayCode{
public static void gray(int n, String prefix)
{
if(n == )
System.out.println(prefix);
else
{
gray(n-,prefix + "");
yarg(n-,prefix + "");
}
}
public static void yarg(int n, String prefix)
{
if(n == )
System.out.println(prefix);
else
{
gray(n-,prefix + "");
yarg(n-,prefix + "");
}
}
public static void main(String[] args)
{
int N = Integer.parseInt(args[]);
gray(N, "");
}
}
运行结果
> java GrayCode 3
000
001
011
010
110
111
101
100
gray code 格雷码 递归的更多相关文章
- [LeetCode] Gray Code 格雷码
The gray code is a binary numeral system where two successive values differ in only one bit. Given a ...
- [LeetCode] 89. Gray Code 格雷码
The gray code is a binary numeral system where two successive values differ in only one bit. Given a ...
- Gray Code - 格雷码
基本概念 格雷码是一种准权码,具有一种反射特性和循环特性的单步自补码,它的循环.单步特性消除了随机取数时出现重大误差的可能,它的反射.自补特性使得求反非常方便.格雷码属于可靠性编码,是一种错误最小化的 ...
- [LintCode] Gray Code 格雷码
The gray code is a binary numeral system where two successive values differ in only one bit. Given a ...
- HDU 5375 Gray code 格雷码(水题)
题意:给一个二进制数(包含3种符号:'0' '1' '?' ,问号可随意 ),要求将其转成格雷码,给一个序列a,若转成的格雷码第i位为1,则得分+a[i].求填充问号使得得分最多. 思路:如果了 ...
- 089 Gray Code 格雷编码
格雷编码是一个二进制数字系统,在该系统中,两个连续的数值仅有一个位数的差异.给定一个代表编码总位数的非负整数 n,打印格雷码序列.格雷码序列必须以0开头.例如, 给定 n = 2, 返回 [0,1,3 ...
- Leetcode89. Gray Code格雷编码
给定一个代表编码总位数的非负整数 n,打印其格雷编码序列.格雷编码序列必须以 0 开头. 示例 1: 输入: 2 输出: [0,1,3,2] 解释: 00 - 0 01 - 1 11 - 3 10 - ...
- 格雷码Gray Code详解
格雷码简介 在一组数的编码中,若任意两个相邻的代码只有一位二进制数不同,则称这种编码为格雷码(Gray Code),另外由于最大数与最小数之间也仅一位数不同,即“首尾相连”,因此又称循环码或反射码.格 ...
- LeetCode:Gray Code(格雷码)
题目链接 The gray code is a binary numeral system where two successive values differ in only one bit. Gi ...
随机推荐
- Off-by-one错误
在迭代循环中,误用> < ≥ ≤符号,有可能导致循环次数多一次或者少一次,就会引发off-by-one错误,混用半开区间和闭区间时,也经常发生此类错误,解决方法是利用最小的输入值去测试代码 ...
- strcmp函数实现及分析
最近看C,看到strcmp函数,对它的实现原型不很清楚,于是到网上搜.网上算法一大堆,看了很多代码后自己做了一下总结 strcmp函数是C/C++中基本的函数,它对两个字符串进行比较,然后返回比较结果 ...
- BZOJP1003 [ZJOI2006]物流运输trans
BZOJP1003 [ZJOI2006]物流运输trans 1003: [ZJOI2006]物流运输trans Time Limit: 10 Sec Memory Limit: 162 MB Sub ...
- javascript 通过IE ActiveX 获得本机内网ip
<HTML><HEAD><TITLE>WMI Scripting HTML</TITLE> <META http-equiv=Content-Ty ...
- yii 权限分级式访问控制的实现(非RBAC法)——已验证
验证和授权——官方文档: http://www.yiichina.com/guide/topics.auth http://www.yiiframework.com/doc/guide/1.1/zh_ ...
- MongoDB:The Definitive Guide CHAPTER 2 Getting Started
MongoDB is very powerful, but it is still easy to get started with. In this chapter we’ll introduce ...
- jquery 1.9里面已经删除了toggle(fn1, fn2)函数
转自:http://blog.sina.com.cn/s/blog_50042fab0101c7a9.html jquery 1.9里面已经删除了toggle(fn1, fn2)函数: 引用 Note ...
- jvm参数设置大全
转自:http://blog.csdn.net/kthq/article/details/8618052 参数说明 -Xmx3550m:设置JVM最大堆内存为3550M. -Xms3550m:设置JV ...
- UIBarButtonItem导航栏添加按钮
1 前言 UIBarButtonItem为导航栏按钮,在导航栏的左侧和右侧,他们具有许多种不同的形状和形式. 2 代码讲解 ZYViewController.m [plain] (void)view ...
- 自定义toast功能
http://download.csdn.net/detail/caryt/8105031