← 返回 apple 的题目列表Combinatorial Product Selection
类型:online_judge
At a fruit store, there are several categories of products, each containing multiple products with prices. Implement an algorithm to select one product from each category to list all possible combinations of products. Explain how to calculate the number of combinations and analyze the complexity.
Input:
products: A two-dimensional list representing the price list of products in each category.
Output:
A two-dimensional list representing all possible product combinations, where each sublist is a possible combination.
Example:
Input:
[[5, 10], [20, 30], [40, 50]]
Output:
[[5, 20, 40], [5, 20, 50], [5, 30, 40], [5, 30, 50], [10, 20, 40], [10, 20, 50], [10, 30, 40], [10, 30, 50]]
Constraints:
The length of each list is in the range of [1, 10], with no more than 10 lists.
Please implement the algorithm and provide several test cases.
Example
Input
[[5, 10], [20, 30], [40, 50]]