生成元组模索引
我正在寻找一种生成所有元组的算法(或类似 C 的实现,没有可用的 itertools) [a_0 a_1 ... a_(n-1)] 使得 0 <= a_i <= i + 1。也欢迎指向文献。
I am looking for an algorithm (or a C-like implementation, no itertools available) which generates all tuples
[a_0 a_1 ... a_(n-1)] such that 0 <= a_i <= i + 1. Pointers to literature are also welcome.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
像这样的东西?
something like this?
这就是所谓的回溯。搜索维基百科有关它。您可以递归或迭代地进行。
阿米尔,他想要介于 0 和 i + 1 之间,而不是介于 0 和 i 之间。我认为在堆栈上传递数组比全局访问它们要慢。
我想你想要这样的东西:
It's called backtracking. Search wikipedia about it. You can do it both recursive or iterative.
Amir, he wants between 0 and i + 1, not between 0 and i. And i think passing arrays on the stack is slower thant accesing them as global.
I think you want something like this: