I was wondering what would be the best way to go about solving the following problem. I was writing this in PHP but it is more of a general programming problem and I guess it involves search algorithms and combinatorics.
Given an array containing multiple arrays/sets of numbers
$a[0] = array(1,2,3,4,5);
$a[1] = array(1,3,5,7,9);
$a[2] = array(2,4,6,8,10);
I would like to draw a number from each array such that the sum of the drawn numbers is the smallest possible. Also the number must be drawn from a unique array index, so in this example you couldn't draw 1, 1, 2. The smallest possible number sequence from the arrays above would be 3, 1, 4 which would give a sum of 8.
Now assume an input array of n
arrays/sets containing each m
numbers, what would be the most logical and efficient way to find the optimal sequence of numbers?