C#:0 & 1 排列
我想列出仅包含 0 和 1 的排列。与二进制类似,但允许可变长度,不必等于 8 长度。例如:
0
1
00
01
10
11
000
001
010
011
100
101
110
111
一直到满足X的长度。这怎么能做到呢?
I want to list permutations with only 0 and 1. Similar to binary but allowing variable lengths, doesn't have to equal 8 length. For example:
0
1
00
01
10
11
000
001
010
011
100
101
110
111
All the way until the length of X is met. How can this be done?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您还可以使用:
不涉及递归:)
You can also use:
Which involves no recursion :)
我会将其作为递归调用来执行,一个函数执行所有特定长度的操作,另一个函数调用所有相关长度的函数。以下完整的 C# 2008 控制台应用程序显示了我的意思:
此输出:
这就是我认为您所追求的。
I would do this as a recursive call, one function to do all of a specific length, another to call that for all relevant lengths. The following complete C# 2008 console application shows what I mean:
This outputs:
which is what I think you were after.