------
## 最终结论
```python
def maxProfit(k, prices):
    if not prices or k == 0:
        return 0

    n = len(prices)
    if k >= n // 2:  # If k is larger than half of the days, we can make as many transactions as we want
        return sum(max(prices[i + 1] - prices[i], 0) for i in range(n - 1))

    # Create a DP table where dp[i][j] represents the max profit on day j with at most i transactions
    dp = [[0] * n for _ in range(k + 1)]

    for i in range(1, k + 1):
        max_diff = -prices[0]  # Initialize the maximum difference
        for j in range(1, n):
            dp[i][j] = max(dp[i][j - 1], prices[j] + max_diff)  # Max profit of not selling today or selling today
            max_diff = max(max_diff, dp[i - 1][j] - prices[j])  # Update the maximum difference

    return dp[k][n - 1]
```