出一个题目

STEM版,合并数学,物理,化学,科学,工程,机械。不包括生物、医学相关,和计算机相关内容。

版主: verdeliteTheMatrix

回复
头像
(ヅ)楼主
论坛支柱
论坛支柱
帖子互动: 549
帖子: 11819
注册时间: 2022年 8月 21日 14:20

出一个题目

帖子 (ヅ)楼主 »

k位格雷码的主要特征:

0. n个数字分别是0到n-1
1. 相邻位只相差一位数字
2. 首尾同样只相差一个数字

举例k = 3,n = 2^k = 8的时候

000
001
011
010
110
111
101
100

用归纳法容易证明格雷码能够一定满足这两个特征.但是这里有个限制,n一定是2^k

要求证明:对于任意正整数n,一定可以构造出一个低配格雷码,满足条件0和1.
FoxMe(令狐)
论坛精英
论坛精英
帖子互动: 155
帖子: 5572
注册时间: 2022年 7月 26日 16:46

Re: 出一个题目

帖子 FoxMe(令狐) »

啥意思?截短不就行了?
头像
(ヅ)楼主
论坛支柱
论坛支柱
帖子互动: 549
帖子: 11819
注册时间: 2022年 8月 21日 14:20

Re: 出一个题目

帖子 (ヅ)楼主 »

FoxMe 写了: 2023年 5月 3日 16:12 啥意思?截短不就行了?
比如n = 7如果你的意思是从n=8(k=3)的格雷码里面选前7个,这7个数字包括了7。
头像
YWY(夜未央)
论坛元老
论坛元老
2023-24年度十大优秀网友
帖子互动: 1338
帖子: 14414
注册时间: 2022年 7月 22日 17:25

Re: 出一个题目

帖子 YWY(夜未央) »

(ヅ) 写了: 2023年 5月 3日 15:17 k位格雷码的主要特征:

0. n个数字分别是0到n-1
1. 相邻位只相差一位数字
2. 首尾同样只相差一个数字

举例k = 3,n = 2^k = 8的时候

000
001
011
010
110
111
101
100

用归纳法容易证明格雷码能够一定满足这两个特征.但是这里有个限制,n一定是2^k

要求证明:对于任意正整数n,一定可以构造出一个低配格雷码,满足条件0和1.
对n做数学归纳法:When n = 1, the claim is clearly true. Let n > 1 and assume that the claim holds for all positive integers less than n. If n = 2k, there exists k位格雷码. So it suffices to prove the claim for n such that 2k < n < 2k+1. By induction hypothesis, there is a 低配格雷码 for n-2k, meaning that we can re-arrange the numbers 0, ..., n-2k-1 such that they 满足条件0和1. Write this 低配格雷码 in k-digit binary, and then add a new digit 1 to the left of each of those k-digit numbers. The result is an arrangement of the numbers 2k, ..., n-1 such that they 满足条件1. Say the first number of this sequence is 1dk-1...d0, in binary. Next, fix a k位格雷码 (for 2k), which is actually a circle that satisfies 条件0和1. So we can make it into a sequence whose last number is dk-1...d0 = 0dk-1...d0 in binary. Note that the difference between 0dk-1...d0 and 1dk-1...d0 is precisely one digit. Now, we can connect the two sequences together to get a 低配格雷码 for n.
持仓抄底锁利,你钱你定
看牛观猪喊熊,自娱自乐
股市变幻莫测,不作不死
赌途曲折无常,吃枣药丸
头像
(ヅ)楼主
论坛支柱
论坛支柱
帖子互动: 549
帖子: 11819
注册时间: 2022年 8月 21日 14:20

Re: 出一个题目

帖子 (ヅ)楼主 »

YWY 写了: 2023年 5月 7日 10:26 对n做数学归纳法:When n = 1, the claim is clearly true. Let n > 1 and assume that the claim holds for all positive integers less than n. If n = 2k, there exists k位格雷码. So it suffices to prove the claim for n such that 2k < n < 2k+1. By induction hypothesis, there is a 低配格雷码 for n-2k, meaning that we can re-arrange the numbers 0, ..., n-2k-1 such that they 满足条件0和1. Write this 低配格雷码 in k-digit binary, and then add a new digit 1 to the left of each of those k-digit numbers. The result is an arrangement of the numbers 2k, ..., n-1 such that they 满足条件1. Say the first number of this sequence is 1dk-1...d0, in binary. Next, fix a k位格雷码 (for 2k), which is actually a circle that satisfies 条件0和1. So we can make it into a sequence whose last number is dk-1...d0 = 0dk-1...d0 in binary. Note that the difference between 0dk-1...d0 and 1dk-1...d0 is precisely one digit. Now, we can connect the two sequences together to get a 低配格雷码 for n.
赞, I am convinced!
回复

回到 “STEM”