У меня есть вектор векторов, скажем vector<vector<int> > items
разных размеров, как показано ниже
1,2,3
4,5
6,7,8
Я хочу создать комбинации с точки зрения декартово произведение этих векторов, как
1,4,6
1,4,7
1,4,8
and so on till
3,5,8
Как я могу это сделать? Я просмотрел несколько ссылок, и я также перечислил их в конце этого поста, но я не могу их интерпретировать, поскольку я не очень хорошо знаком с языком. Может ли какое-то тело помочь мне с этим.
#include <iostream>
#include <iomanip>
#include <vector>
using namespace std;
int main()
{
vector<vector<int> > items;
int k = 0;
for ( int i = 0; i < 5; i++ ) {
items.push_back ( vector<int>() );
for ( int j = 0; j < 5; j++ )
items[i].push_back ( k++ );
}
cartesian ( items ); // I want some function here to do this.
}
Эта программа имеет векторы одинаковой длины, и я поставил это так, чтобы было легче понять мою структуру данных. Это будет очень полезно, даже если кто-то использует ответы других людей из других ссылок и интегрируется с ними, чтобы получить результат. большое спасибо
Пара ссылок, которые я посмотрел на одну из двух программ из: программы