2020-1ํ•™๊ธฐ, ๋Œ€ํ•™์—์„œ โ€˜์•Œ๊ณ ๋ฆฌ์ฆ˜โ€™ ์ˆ˜์—…์„ ๋“ฃ๊ณ  ๊ณต๋ถ€ํ•œ ๋ฐ”๋ฅผ ์ •๋ฆฌํ•œ ๊ธ€์ž…๋‹ˆ๋‹ค. ์ง€์ ์€ ์–ธ์ œ๋‚˜ ํ™˜์˜์ž…๋‹ˆ๋‹ค :)

1 minute read

2020-1ํ•™๊ธฐ, ๋Œ€ํ•™์—์„œ โ€˜์•Œ๊ณ ๋ฆฌ์ฆ˜โ€™ ์ˆ˜์—…์„ ๋“ฃ๊ณ  ๊ณต๋ถ€ํ•œ ๋ฐ”๋ฅผ ์ •๋ฆฌํ•œ ๊ธ€์ž…๋‹ˆ๋‹ค. ์ง€์ ์€ ์–ธ์ œ๋‚˜ ํ™˜์˜์ž…๋‹ˆ๋‹ค :)


DP๋Š” ์ •๋ง ์•Œ๊ณ ๋ฆฌ์ฆ˜ PS๋ฅผ ํ•˜๋ฉด์„œ, ๋น ์งˆ ์ˆ˜ ์—†๋Š” ์ฃผ์ œ๋‹ค!! ์‹ค์ œ ๋™์ž‘ํ•˜๋Š” ๋งŽ์€ ์•Œ๊ณ ๋ฆฌ์ฆ˜์ด DP์˜ ํ…Œํฌ๋‹‰์„ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ์œผ๋ฉฐ, ์šฐ๋ฆฌ๋Š” DP๊ฐ€ ๊ฐ€์ ธ๋‹ค์ฃผ๋Š” ํšจ์œจ์„ฑ์„ ๋Š˜ ๋ˆ„๋ฆฌ๊ณ  ์žˆ๋‹ค.

DP์˜ ์ปจ์…‰์€ ์•„๋ž˜์™€ ๊ฐ™๋‹ค.

1. Identifying a collection of subproblems.

2. Tackling them one by one.
2.1. smallest first.
2.2. using the result of small ones to solve the larger ones.
2.3. repeat this until solve the whole problems!

์ข€๋” ์ถ”์ƒํ™”ํ•œ ๊ด€์ ์—์„œ DP๋ฅผ ๋ฐ”๋ผ๋ณด๋ฉด, โ€œDAG ordering on btw subproblemsโ€, and โ€œsmaller subproblem์„ ํ‘ธ๋Š” ๋ฐฉ์‹์ด bigger subproblem์„ ํ‘ธ๋Š” ๋ฐ์— ๊ทธ๋Œ€๋กœ ์‚ฌ์šฉ๋œ๋‹คโ€๋ผ๊ณ  ๋งํ•  ์ˆ˜ ์žˆ๋‹ค.


DP ํ…Œํฌ๋‹‰์˜ ์ค‘์‹ฌ์€ <Memoization>์ด๋ผ๊ณ  ํ•  ์ˆ˜ ์žˆ๋‹ค. subproblem์˜ ๊ฒฐ๊ณผ๋ฅผ ๋ฐ”ํƒ•์œผ๋กœ problem์„ ํ’€๊ธฐ ๋•Œ๋ฌธ์— ๋‹น์—ฐํžˆ subproblem์˜ ๊ฒฐ๊ณผ๋ฅผ ์ €์žฅ(memo)ํ•  ํ•„์š”๊ฐ€ ์žˆ๊ณ , ์ด๋•Œ ์“ฐ๋Š” ํ…Œํฌ๋‹‰์ด ๋ฐ”๋กœ <Memoization>์ด๋‹ค. ๊ฐ„๋‹จํžˆ ๋งํ•˜์ž๋ฉด, <Memoization>์€ ๊ทธ๋ƒฅ subproblem์˜ ๊ฒฐ๊ณผ๋ฅผ ๋ฐฐ์—ด์— ์ €์žฅํ•œ๋‹ค!์ด๋‹ค. ์ด Memoization์„ ์–ด๋–ป๊ฒŒ ํ• ๊ป€์ง€ ๊ณ ๋ฏผํ•˜๋Š” ๊ฒƒ ์—ญ์‹œ DP์—์„œ ์ค‘์š”ํ•œ ๋ถ€๋ถ„์ด๊ธฐ ๋•Œ๋ฌธ์— ๋งŽ์€ ์—ฐ์Šต์ด ํ•„์š”ํ•˜๋‹ค.


์ด๋ฒˆ ์ฑ•ํ„ฐ์—์„œ ๋‹ค๋ฃจ๋Š” ๋ฌธ์ œ๋“ค์€ ์•„๋ž˜์™€ ๊ฐ™๋‹ค.

(์ƒ๋‹นํžˆ ๋งŽ์€ ๋ฌธ์ œ๊ฐ€ DP์˜ ํ…Œํฌ๋‹‰์„ ์‚ฌ์šฉํ•œ๋‹ค. ๊ทธ๋งŒํผ DP๊ฐ€ ์ค‘์š”ํ•˜๋‹ค๋Š” ๋ง!)

Categories:

Updated: