public int maxProfit(int k, int[] prices) {
		if (prices.length == 0)
			return 0;
		if (k >= prices.length)
			return solveMaxProfit(prices); // k is larger than operaitons

		int[] local = new int[k + 1]; 
		int[] global = new int[k + 1];

		for (int i = 0; i < prices.length - 1; i++) {
			int diff = prices[i + 1] - prices[i];
			for (int j = k; j >= 1; --j) {
				local[j] = Math.max(global[j - 1] + Math.max(diff, 0), local[j]
						+ diff);
				global[j] = Math.max(global[j], local[j]);
			}
		}

		return global[k];

	}