TachyonCalculus
H
Jakarta Raya, Indonesia
Repeat after me:

∇ ⋅ E = ρ / ε0
∇ ⋅ B = 0
∇ × E = - ∂B / ∂t
∇ × B = μ0 (J + ε0 ∂E / ∂t)
Repeat after me:

∇ ⋅ E = ρ / ε0
∇ ⋅ B = 0
∇ × E = - ∂B / ∂t
∇ × B = μ0 (J + ε0 ∂E / ∂t)
当前离线
Information
Submission for Leetcode Problem 188. Best Time to Buy and Sell Stock IV (Hard)
(Java) 2D Dynamic Programming

Problem link [leetcode.com]
I don't know what to write so here's my recently accepted Leetcode submission:

class Solution {
⠀⠀⠀public int maxProfit(int k, int[] prices) {
⠀⠀⠀⠀⠀⠀int len = prices.length;
⠀⠀⠀⠀⠀⠀int[][] dp = new int[len + 1][2 * k + 1];
⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀for (int j = 1; j <= 2 * k; j++) {
⠀⠀⠀⠀⠀⠀⠀⠀⠀for (int i = j; i <= len; i++) {
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀int multiplier = j % 2 == 0 ? 1 : -1;
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀int product = multiplier * prices[i - 1];
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀if (i == j) {
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀dp[i][j] = product + dp[i - 1][j - 1];
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀} else {
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀dp[i][j] = Math.max(
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀dp[i - 1][j], product + dp[i - 1][j - 1]);
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀}
⠀⠀⠀⠀⠀⠀⠀⠀⠀}
⠀⠀⠀⠀⠀⠀}

⠀⠀⠀⠀⠀⠀int result = 0;
⠀⠀⠀⠀⠀⠀for (int i = 2; i <= 2 * k; i += 2)
⠀⠀⠀⠀⠀⠀⠀⠀⠀result = Math.max(result, dp[len][i]);
⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀return result;
⠀⠀⠀}
}
截图展柜
Forza Horizon 4
最新动态
总时数 715 小时
最后运行日期:3 月 14 日
100 点经验值
成就进度   133 / 520
总时数 9.1 小时
最后运行日期:3 月 8 日
总时数 68 小时
最后运行日期:2 月 28 日
200 点经验值
成就进度   81 / 164
留言
/) Leomate (\ 2014 年 12 月 7 日 上午 11:18 
Hi bim :3