问题描述
我有一个向量向量说 vector
如下
I've a vector of vectors say vector<vector<int> > items
of different sizes like as follows
我想根据这些向量的笛卡尔积来创建组合,例如
I want to create combinations in terms of Cartesian product of these vectors like
我该怎么做?我查了几个链接,我也在这篇文章的末尾列出了它们,但我无法解释它,因为我不太熟悉这种语言.有没有机构可以帮我解决这个问题.
How can I do that ? I've looked up several links and I've also listed them at the end of this post but I'm not able to interpret that as I'm not that familiar with the language. Could some body help me with this.
这个程序有等长的向量,我把它放在那里是为了更容易理解我的数据结构.即使有人使用来自其他链接的其他答案并与之集成以获得结果,这也会非常有帮助.非常感谢
This program has equal length vectors and I put this so that it will be easier to understand my data structure. It will be very helpful even if somebody uses others answers from other links and integrate with this to get the result. Thank you very much
我看了几个链接一个两个程序来自:程序
Couple of links I looked at one Two Program from : program
推荐答案
首先,我将向您展示一个递归版本.
First, I'll show you a recursive version.
现在,我将向您展示我从@John 无耻地窃取的递归 迭代版本:
Now, I'll show you the recursive iterative version that I shamelessly stole from @John :
程序的其余部分几乎相同,仅显示cart_product
函数.
The rest of the program is pretty much the same, only showing the cart_product
function.
这篇关于如何创建向量向量的笛卡尔积?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!