Algorithm/๋™์ ๊ณ„ํš๋ฒ• 4

[Dynamic Programming] ๋™์ „๋ฐ”๊พธ๊ธฐ - ์ดˆ๊ธ‰

์œ ํŠญ ๋งใ…‹ ๐Ÿ“‹ LeetCode 322๋ฒˆ Coin Change - LeetCode Can you solve this real interview question? Coin Change - You are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of money. Return the fewest number of coins that you need to make leetcode.com F(n)์ด ํ•ฉํ•ด์„œ n์ด ๋˜๋Š” coins์˜ ํ•ฉ์ด๋ผ๊ณ  ์ •ํ•ด์ค€๋‹ค. F(11)์ด ๋˜๋Š” ๊ฒฝ์šฐ์˜ ์ˆ˜๋Š” ( F(11-1) or F(11-2) or F(11-5) ..

[Dynamic Programming] ์ตœ์†Œ ๋น„์šฉ ๊ตฌํ•˜๊ธฐ - ์ดˆ๊ธ‰

์œ ํŠญ ๋งใ…‹ ๐Ÿ“‹ LeetCode 64๋ฒˆ Minimum Path Sum - LeetCode Can you solve this real interview question? Minimum Path Sum - Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path. Note: You can only move either down or rig leetcode.com grid cost [[ 1, 3, 1 ], [[ 1, 4, 5 ], [ 1, 5, 1 ], → [ 2, _, _ ], [ 4, 2, 1 ]] ..

[Dynamic Programming] ๊ณ„๋‹จ ์˜ค๋ฅด๊ธฐ - ์ดˆ๊ธ‰

→ ๐Ÿ“‹ LeetCode 70๋ฒˆ Climbing Stairs - LeetCode Can you solve this real interview question? Climbing Stairs - You are climbing a staircase. It takes n steps to reach the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top? Example 1: Input: n = 2 Outpu leetcode.com ์˜ฌ๋ผ๊ฐ€์•ผ ํ•˜๋Š” ๊ณ„๋‹จ์˜ ์ˆ˜: n n์œผ๋กœ ์˜ฌ๋ผ๊ฐ€๊ธฐ ์œ„ํ•œ ๊ฒฝ์šฐ์˜ ์ˆ˜๋Š” n-1์—์„œ 1์นธ or n-2์—์„œ 2์นธ ์˜ฌ๋ผ ๊ฐ€๋Š” ๋‘ ๊ฐ€์ง€ ๋ฐฉ๋ฒ•์ด ์žˆ๋‹ค. -> ํ”ผ๋ณด๋‚˜์น˜ ์ˆ˜์™€ ..

[Dynamic Programming] ๋‹ค์ด๋‚˜๋ฏน ํ”„๋กœ๊ทธ๋ž˜๋ฐ์˜ ๊ธฐ์ดˆ

์ฝ”๋“œ์—†๋Š” ํ”„๋กœ๊ทธ๋ž˜๋ฐ๋‹˜์˜ ๊ฐ•์˜ ์ˆ˜๊ฐ• Dynamic Programming ์กฐ๊ฑด ๋ฌธ์ œ๊ฐ€ ๋” ์ž‘์€ subproblem์œผ๋กœ ์ชผ๊ฐœ์งˆ ๋•Œ subproblem์˜ solution์œผ๋กœ ๋” ํฐ problem์˜ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ์„ ๋•Œ ๋‚˜๋ˆˆ subprolem์ด ๊ฒน์น  ๋•Œ -> ํ•„์š”ํ•œ ๊ณ„์‚ฐ ์ˆ˜๋ฅผ ์ค„์ผ ์ˆ˜ ์žˆ๋‹ค. ํ”ผ๋ณด๋‚˜์น˜ ์ˆ˜์—ด ๋Œ€ํ‘œ์ ์ธ ๋™์  ํ”„๋กœ๊ทธ๋ž˜๋ฐ์˜ ์˜ˆ์‹œ ํ”ผ๋ณด๋‚˜์น˜ ์ˆ˜์—ด F(7)์„ ๊ตฌํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด? F(7) = F(6) + F(5) F(7) = F(5) + F(4) + F(4) + F(3) F(7) = F(4) + F(3) + F(3) + F(2) + F(3) + F(2) + F(2) + F(1) . . . ์‹œ๊ฐ„ ๋ณต์žก๋„๋Š”? ์ธต์ด ๋Š˜์–ด๋‚  ๋•Œ๋งˆ๋‹ค 2๊ฐ€ ๊ณฑํ•ด์ง€๊ณ  ์ด n๊ฐœ์˜ ์ธต์ด๊ธฐ ๋•Œ๋ฌธ์— $$ O(2^n) $$ def fib_naive..