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

2 minute read

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


์ด์ „์˜ โ€œInterval Scheduling and Partitioningโ€ ํฌ์ŠคํŠธ์—์„œ Interval์„ ์Šค์ผ€์ฅด ํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ์‚ดํŽด๋ณด์•˜๋‹ค. ์ด๋•Œ๋Š” Greedy ํ•œ ๋ฐฉ์‹์œผ๋กœ ์ ‘๊ทผํ•ด ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ–ˆ๋‹ค.

Greedy๋Š” Interval์ด ๋ชจ๋‘ ๋™์ผํ•œ weight๋ฅผ ๊ฐ–๋Š”๋‹ค๋ฉด ์ž˜ ๋™์ž‘ํ•œ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ ์ด๋ฒˆ์—๋Š” ๊ฐ Interval์— weight $W_i$๊ฐ€ ์žˆ์–ด ๊ฐ€์ค‘ํ•ฉ์„ ์ตœ๋Œ€ํ™” ํ•˜๋„๋ก ๋ฌธ์ œ๋ฅผ ํ’€์–ด์•ผ ํ•œ๋‹ค. ์ด ๊ฒฝ์šฐ์—๋Š” Greedy๊ฐ€ ์•„๋‹ˆ๋ผ DP๋กœ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•ด์•ผ ํ•œ๋‹ค!


๋จผ์ € ๋ฌธ์ œ๋ฅผ ๊ธฐ์ˆ ํ•ด๋ณด์ž.

A set of $n$ jobs, job $j$ starts at $s_j$, finishes at $f_j$ and has weight $w_j$. Find a maximum weight subset of โ€œmutually compatibleโ€ jobs.

๋จผ์ € Greedy ๋ฐฉ์‹๊ณผ ๋™์ผํ•œ๊ฒŒ interval์€ finish time $f_j$๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์ •๋ ฌํ•œ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ํ•จ์ˆ˜ $p(j)$๋ฅผ ์ •์˜ํ•ด job $j$์™€ compatible ํ•˜๋ฉด์„œ ๊ฐ€์žฅ ๋น ๋ฅธ job $i$๋ฅผ ๊ตฌํ•ด๋ณด์ž.

  • $p(j)$: last index $i < j$ s.t. job $i$ is compatible with $j$.

๋งˆ์ง€๋ง‰์œผ๋กœ $DP[j]$๋ฅผ โ€œvalue of optimal solution to the problem consisting of jobs from $1$ tot $j$โ€ ์ •์˜ํ•˜๋ฉด ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•  ์ค€๋น„๊ฐ€ ๋๋‚ฌ๋‹ค! ๐Ÿ˜Ž

$DP[j]$๋ฅผ ์—…๋ฐ์ดํŠธ ํ•˜๋Š” ๊ทœ์น™์—๋Š” 2๊ฐ€์ง€๊ฐ€ ์žˆ๋‹ค.

1. select job $j$

then, we cannot use incompatible jobs, so

\[DP[j] = w_j + DP[p(j)]\]

2. not select job $j$

then, just use previous optimal result

\[DP[j] = DP[j-1]\]

์œ„ ๊ทœ์น™์„ ์ข…ํ•ฉํ•˜๋ฉด ์•„๋ž˜์™€ ๊ฐ™๋‹ค.

\[DP[j] = \max \left\{ w_j + DP[p(j)], \; DP[j-1] \right\}\]

(์•„๋ž˜์˜ ๊ธ€์€ ์ €์˜ ๋‡Œ-ํ”ผ์…œ ์ž…๋‹ˆ๋‹ค ๐Ÿคช)

<Interval Scheduling> ๋ฌธ์ œ์—์„œ๋„ Greedy์™€ DP๊ฐ€ ๋‹ค๋ฅด๋‹ค๋Š” ๋Š๋‚Œ์„ ๋ฐ›์„ ์ˆ˜ ์žˆ๋‹ค. Greedy๋Š” ์ด ์ ‘๊ทผ์ด ์ตœ์ ํ•ด๋ฅผ ๋ณด์žฅํ•จ์„ ์™„์ „ํžˆ ํ™•์‹ ํ•˜๊ฑฐ๋‚˜ ์ง์ ‘ โ€˜์ฆ๋ช…โ€™ํ•ด์•ผ ํ•œ๋‹ค. ์ด ๊ณผ์ •์—์„œ ๋ฃฐ์ด ๋„ˆ๋ฌด ๋ณต์žกํ•˜๋‹ค๋ฉด DP๊ฐ€ ์˜ฌ๋ฐ”๋ฅธ ์„ ํƒ์ผ ์ˆ˜ ์žˆ๋‹ค. ๋ฐ˜๋ฉด์— DP๋Š” ํŠน๋ณ„ํžˆ โ€˜์ฆ๋ช…โ€™์„ ํ•  ํ•„์š˜์—†๋‹ค. ๋ฌธ์ œ๋ฅผ Greedy ๋งŒํผ ๋‹จ์ˆœํ•˜๊ฒŒ ํ•ด๊ฒฐํ•˜์ง„ ์•Š์ง€๋งŒ ๊ฐ€๋Šฅํ•œ ๋ชจ๋“  ๊ฒฝ์šฐ๋ฅผ DAG์˜ ํ˜•ํƒœ๋กœ ๊ณ ๋ คํ•˜์—ฌ ๋‹ต์„ ์œ ๋„ํ•˜๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค!

<Interval Scheduling> ๋ฌธ์ œ์™€ ๊ด€๋ จ๋œ ๋ฐฑ์ค€ ๋ฌธ์ œ๋Š” ์•„์ง ์ฐพ์ง€ ๋ชป ํ–ˆ๋‹ค. ์ถ”ํ›„์— ์ฐพ๊ฒŒ ๋˜๋ฉด ์—…๋ฐ์ดํŠธ ํ•˜๊ฒ ๋‹ค.

Categories:

Updated: