[JavaScript/section 10] 04 - ๋™์ „๊ตํ™˜
ยท
Algorithm/์ธํ”„๋Ÿฐ(inflearn)
๐Ÿ“Œ ๋™์ „๊ตํ™˜(๋ƒ…์ƒ‰ ์•Œ๊ณ ๋ฆฌ์ฆ˜) ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์—ฌ๋Ÿฌ ๋‹จ์œ„์˜ ๋™์ „๋“ค์ด ์ฃผ์–ด์ ธ ์žˆ์„๋•Œ ๊ฑฐ์Šค๋ฆ„๋ˆ์„ ๊ฐ€์žฅ ์ ์€ ์ˆ˜์˜ ๋™์ „์œผ๋กœ ๊ตํ™˜ํ•ด์ฃผ๋ ค๋ฉด ์–ด๋–ป๊ฒŒ ์ฃผ๋ฉด ๋˜๋Š”๊ฐ€? ๊ฐ ๋‹จ์œ„์˜ ๋™์ „์€ ๋ฌดํ•œ์ • ์“ธ ์ˆ˜ ์žˆ๋‹ค. ์ž…๋ ฅ์„ค๋ช… ์ฒซ ๋ฒˆ์งธ ์ค„์—๋Š” ๋™์ „์˜ ์ข…๋ฅ˜๊ฐœ์ˆ˜ N(1
[JavaScript/section 10] 02 - ๋Œ๋‹ค๋ฆฌ ๊ฑด๋„ˆ๊ธฐ
ยท
Algorithm/์ธํ”„๋Ÿฐ(inflearn)
๐Ÿ“Œ 02 - ๋Œ๋‹ค๋ฆฌ ๊ฑด๋„ˆ๊ธฐ(DP) ์ฒ ์ˆ˜๋Š” ํ•™๊ต์— ๊ฐ€๋Š”๋ฐ ๊ฐœ์šธ์„ ๋งŒ๋‚ฌ๋‹ค. ๊ฐœ์šธ์€ N๊ฐœ์˜ ๋Œ๋กœ ๋‹ค๋ฆฌ๋ฅผ ๋งŒ๋“ค์–ด ๋†“์•˜๋‹ค. ์ฒ ์ˆ˜๋Š” ๋Œ ๋‹ค๋ฆฌ๋ฅผ ๊ฑด๋„ ๋•Œ ํ•œ ๋ฒˆ์— ํ•œ ์นธ ๋˜๋Š” ๋‘ ์นธ์”ฉ ๊ฑด๋„ˆ๋›ฐ๋ฉด์„œ ๋Œ๋‹ค๋ฆฌ๋ฅผ ๊ฑด๋„ ์ˆ˜ ์žˆ๋‹ค. ์ฒ ์ˆ˜๊ฐ€ ๊ฐœ์šธ์„ ๊ฑด๋„ˆ๋Š” ๋ฐฉ๋ฒ•์€ ๋ช‡๊ฐ€์ง€์ผ๊นŒ? ๐Ÿ“ ์†Œ์Šค ์ฝ”๋“œ ์ฐธ๊ณ ) ๊ณ„๋‹จ์˜ค๋ฅด๊ธฐ function solution(n) { let answer = 0; let dy = Array.from({ length: n + 2 }, () => 0); dy[1] = 1; dy[2] = 2; for (let i = 3; i
_์„ฑํ˜ธ_
'DP' ํƒœ๊ทธ์˜ ๊ธ€ ๋ชฉ๋ก