What is the optimal way to find unique combinations of N sets of integers This is a simplification of a real world problem and only a small piece at that.

Example sets are

----------------------       ------------------------------------  
| Set1 | Set2 | Set3 |  OR   | Set1 | Set2 | Set3 | Set4 | Set5 |
|--------------------|       |--------------------|--------------
| 1    | 10   | 40   |       | 1    | 1    | 1    | 1    | 1    |
| 2    | 12   | 45   |       | 2    | 2    | 2    | 2    | 2    |
| 3    | 13   | 51   |       | 3    | 3    | 3    | 3    | 3    |
| 4    | 20   | 61   |       | 4    | 4    | 4    | 4    | 4    |
| 5    | 25   | 76   |       | 5    | 5    | 5    | 5    | 5    |
|      | 31   | 78   |       ------------------------------------
|      |      | 81   |
----------------------       


Real world constraints are


Up to 12 sets
N numbers in each set
Only care about distinct combinations - (112), (211) and (121) are considered the same.


Example with desired result

----------------------
| Set1 | Set2 | Set3 |
|---------------------
| 1    | 1    | 1    |
| 2    | 2    | 2    |
| 3    | 3    | 3    |
----------------------
Results: [1,1,1],[1,1,2],[1,1,3],[1,2,2],[1,2,3],[1,3,3],[2,2,2],[2,2,3],[2,3,3],[3,3,3]


Generally real world examples tend to either be like the first example where there are a variable number in each set and they are different in each set, or like the second where there are the same items in each set. However there are no hard and fast rules.

A real world example of the latter is 10 sets with 40 values in each. To naively iterate that example would be $1x10^{16}$ iterations.

Are there any optimal algorithms I can implement to find distinct combinations? I am hoping that there is something clever that can be done when there are the same items in different sets, somehow excluding them once certain conditions are met, but i have failed to think of or find one.
This may be wrong
I don't follow the multiple set of the set input part of question    

Have a loop for each N  

Assume N = 3
L is length of array A

for(i = 0; i &lt; L-2; i++) 
    for(j = i + 1; j &lt; L-1; j++) 
        for(k = j + 1; k &lt; L; k++)
            A[i], A[j], A[k]


I write poker software and this matches the number of combinations