diff --git a/HamSungJun/DynamicProgramming/Solution_1137.ts b/HamSungJun/DynamicProgramming/Solution_1137.ts new file mode 100644 index 0000000..ab7945e --- /dev/null +++ b/HamSungJun/DynamicProgramming/Solution_1137.ts @@ -0,0 +1,15 @@ +function tribonacci (n: number): number { + if (n <= 1) return n + if (n === 2) return 1 + let t0 = 0 + let t1 = 1 + let t2 = 1 + let acc = 0 + for (let i = 3; i <= n; i++) { + acc = t2 + t1 + t0 + t0 = t1 + t1 = t2 + t2 = acc + } + return acc +}; diff --git a/HamSungJun/DynamicProgramming/Solution_338.ts b/HamSungJun/DynamicProgramming/Solution_338.ts new file mode 100644 index 0000000..616f0f7 --- /dev/null +++ b/HamSungJun/DynamicProgramming/Solution_338.ts @@ -0,0 +1,14 @@ +function countBits (n: number): number[] { + if (n === 0) return [0] + const DP: number[] = new Array(n + 1) + DP[0] = 0 + DP[1] = 1 + for (let i = 2; i <= n; i++) { + if (Number.isInteger(Math.sqrt(i / 2))) { + DP[i] = 1 + } else { + DP[i] = DP[Math.floor(i / 2)] + (i % 2 === 0 ? 0 : 1) + } + } + return DP +}; diff --git a/HamSungJun/DynamicProgramming/Solution_746.ts b/HamSungJun/DynamicProgramming/Solution_746.ts new file mode 100644 index 0000000..334d331 --- /dev/null +++ b/HamSungJun/DynamicProgramming/Solution_746.ts @@ -0,0 +1,10 @@ +function minCostClimbingStairs (cost: number[]): number { + const DP = new Array(cost.length).fill(0) + for (let i = 2; i < cost.length; i++) { + DP[i] = Math.min( + DP[i - 1] + cost[i - 1], + DP[i - 2] + cost[i - 2] + ) + } + return DP[DP.length - 1] +};