Algorithm to get Cartesian product
问题 I have an array like [0,2,3,0,1] as input , and I need to find Cartesian product of {0}x{0,1,2}x{0,1,2,3}x{0}x{0,1} , more precisely I need to have output as following. Input: [0, 2, 3, 0, 1] Output: [0, 0, 0, 0, 0] [0, 0, 0, 0, 1] [0, 0, 1, 0, 0] [0, 0, 1, 0, 1] [0, 0, 2, 0, 0] [0, 0, 2, 0, 1] [0, 0, 3, 0, 0] [0, 0, 3, 0, 1] [0, 1, 0, 0, 0] [0, 1, 0, 0, 1] [0, 1, 1, 0, 0] [0, 1, 1, 0, 1] [0, 1, 2, 0, 0] [0, 1, 2, 0, 1] [0, 1, 3, 0, 0] [0, 1, 3, 0, 1] [0, 2, 0, 0, 0] [0, 2, 0, 0, 1] [0, 2, 1,