Nice solution. Just refine the code a little bit.

def maxProfit(k, prices):
n = len(prices)
if k > n/2: # if k is too large, all potential profit can be earned
return sum([prices[i] - prices[i-1] for i in range(1, n) \
if prices[i] > prices[i-1] ])
f, fnew = [0] * n, [0] * n # ping-pong dp, maximum profit can get then
for _ in range(k):
tmax = - prices[0] # the money I have today
for i in range(1, n):
fnew[i] = max(fnew[i-1], prices[i] + tmax) # do nothing or sell one
tmax = max(tmax, f[i] - prices[i]) # max money after this day
f, fnew = fnew, [0] * n
return f[n-1]
'''