åçè¨ç»æ³ (dynamic programming, DP) ã¯ã¤ã¡ã¼ã¸ã»ã¡ã³ã¿ã«ã¢ãã«ãæ´ãã¾ã§ã®ãã¼ãã«ãä¸ã é«ããããªæ°ããã¾ãã
ä¸ä¾ã示ãã¾ãããå¿ ãããå ¨é¨ã®åé¡ãä¸è²«ãã¦èª¬æã§ããã¨ã¯éããªãã®ã§ãããã¤ãã®ã¤ã¡ã¼ã¸ãæã£ã¦ããã¨ããããããã¾ããï¼ã©ããããã«åºå·ããå¿ è¦ã¯ãªãã¨ãããã¨ï¼ã
æ°å¼ããããªãã«åºã¦ãã¾ãããè¦æãªäººã¯æ·±å¼å¸ã¨ãããªããè½ã¡ã¤ãã¦èªãã§ããããã¨ããããã§ãã
æ°å¼ã«é¢ãã¦è£è¶³
Python 風ãªæ¬ä¼¼ã³ã¼ãã§è»½ã説æãã¦ããã¾ãã
$$\sum_{x\in S} f(x)$$
ããã¯ãä¸è¨ã®é¢æ°ã®è¿ãå¤ã¨åããã®ã表ãã¦ããã¨æã£ã¦ãã ããã$\sum$ ã¯ã·ã°ã (sigma) ã¨èªã¿ã¾ãã
def sigma(S, f): res = 0 for x in S: res += f(x) return res
æ
£ãã¦ãã人㯠sum(map(f, S))
ã ã¨æã£ã¦ã大ä¸å¤«ã§ãã
$$\max S$$
ããã¯ä¸è¨ã§ãã
def maximum(S): res = -oo # -âãããªãã¡ãã®åã®æå°å¤ã§åæå for x in S: res = min(res, x) return res
æ
£ãã¦ãã人ã¯ãmax([-oo, *S])
ã ã¨æã£ã¦ã大ä¸å¤«ã§ãã
$$ \{f(x) \mid x\in S\}$$
ããã¯ä¸è¨ã§ãã
def make_set(S, f): res = set() for x in S: res.add(f(x)) return res
æ
£ãã¦ãã人ã¯ãset(f(x) for x in S)
ã¨ã set(map(f, S))
ã ã¨æã£ã¦ã大ä¸å¤«ã§ãã
ã¾ãã$f(i, j) \triangleq$ ($i$ ã $j$ ã®å¼) ã¨ãã表è¨ã¯ã左辺ã®è¡¨è¨ãå³è¾ºã®å 容ã§å®ç¾©ãã¾ãããã¨ããæå³ã§ãã$f(i, j) \coloneqq \dots$ ã $f(i, j) \stackrel{\text{def}}{=} \dots$ ãªã©ã¨æ¸ã人ããã¾ãã
å°å ¥
解説ã§ããããããã§å®ç¾©ããã DP ã§è¨ç®ããã°ããã§ãããããããé·ç§»ã® DP ãããã°ããã§ãããªã©ã¨è¨ãããã ãã§ãã©ãèãã¦ã©ãæãã¤ãã®ãã身ã«ã¤ããã®ã大å¤ã ã£ããããªè¨æ¶ãããã¾ããæè¿ã®äººã ãã©ãæã£ã¦ããã®ãã¯ãã¾ããããã¾ãããããã³ã¡ãããå§ããé ï¼ãã¶ã 7 å¹´ãããåï¼ï¼ã¯ããããå°è±¡ã§ããã
ãå é $i$ åè¦ãã¨ãã®ä½ã ã®å¤ãã¨ããå é $i$ åè¦ã¦ä½ã ã®å¤ã $j$ ã®ã¨ãã®ä½ã ã®å¤ãã¨ãè¨ããã¦ããããªãã§å é $i$ åãè¦ããã¨æã£ãã®ï¼ãã¨ããæ°æã¡ã«ãªã£ã¦ãã¾ããã
ããã«é¢ãã¦ã¯ãå é $i$ åãè¦ã¦èããã°å é $i+1$ åã®å ´åã®çããããããããªãã¼ã·ãã¯ãªåé¡ããæåã¯åºãªãã¨ããã®ãããããã§ãã ä¸ç´ä»¥ä¸ã«ãªã£ã¦ããã°ããã§ãªãå½¢å¼ã®åé¡ãåºã¦ãã¾ãï¼å¾è¿°ï¼ã
ãèªæãªã±ã¼ã¹ã¯ãªã«ãã§ããããããèããããéèªæãªã±ã¼ã¹ã¯ãªã«ãããããã¯ãããã±ã¼ã¹ãèããä¸ã§ãã³ãã«ãªããããèªæãªã±ã¼ã¹ã¯ãªã«ããã¨ããèãæ¹ãåºæ¬ã§ãã
DP ãæç´ã«çºãã
ãããªããå é $i$ åãè¦ãã¨ãã®ä½ã ã®å¤ãã¨ããã®ãèããã®ã§ã¯ãªãããå é $i$ åãè¦ãã¨ãã«èããããã±ã¼ã¹å ¨ä½ãã¨ããã®ãèãã¦ã¿ããã¨ã«ãã¾ãããã ããããµãã¯åé¡ã® DP ãä¾ã¨ãã¦ä½¿ãã¾ãã
$i$ çªç®ã®ååãéã $w_i$ãä¾¡å¤ $v_i$ ã®ã¨ããçµ $(i, w_i, v_i)$ ã¨ãã¦è¡¨ããã¨ã«ãã¾ãã$i$ 㯠$0$ ããå§ãããã¨ã«ãã¾ãã
$\gdef\dp{\operatorname{dp}}$ $\dp[i][j] \triangleq$ (å é $i$ åã®ååããããã¤ãé¸ã³ãéããã¡ããã© $j$ ã«ããååã®é¸ã³æ¹å ¨ä½ãããªãéå)
ã¨ãã¦ã¿ã¾ãã ãå é $i$ åãã§é¸ã¹ãã®ã¯ã$0$ çªç®, $1$ çªç®, ..., $i-1$ çªç®ã§ãããã¨ã«æ³¨æãã¾ãããã$i$ çªç®ã¯é¸ã¹ã¾ããã
ã¾ãã$\dp[0][0]$ ãèãã¾ããå é $0$ åã®ååããããã¤ãé¸ãã§éããã¡ããã© $0$ ã«ããé¸ã³æ¹ã¯ã$\emptyset$ï¼ããªãã¡ããªã«ãé¸ã°ãªãï¼ã®ã¿ãªã®ã§ã$\dp[0][0] = \{\emptyset\}$ ã¨ãããã¾ãã
ã¾ãã$\dp[0][1]$ ã«ã¤ãã¦ãèãã¦ã¿ã¾ããå é $0$ åã®ååããããã¤ãé¸ãã§éããã¡ããã© $1$ ã«ããé¸ã³æ¹ã¯åå¨ããªãã®ã§ã$\dp[0][1] = \{\} = \emptyset$ ã¨ãããã¾ãã åæ§ã«ã$\dp[0][j] = \emptyset$ ($j>0$) ãè¨ãã¾ãã
ç¶ãã¦ã$\dp[i][j]$ ($i>0$) ã«ã¤ãã¦èãã¾ãã
å é $i$ åã®ã¿ã®ååããããã¤ãé¸ãã§éããã¡ããã© $j$ ã«ããæ¹æ³ã¯ã
- $i$ åç®ã®ååï¼$i-1$ çªï¼ã¯é¸ã°ããå é $i-1$ åã®ã¿ã®ååããããã¤ãé¸ãã§éããã¡ããã© $j$ ã«ãã
- $i$ åç®ã®ååãé¸ã³ï¼ããªãã¡éã $w_{i-1}$ ãå¢ããï¼ãå
é $i-1$ åã®ååããããã¤ãé¸ãã§éã $j-w_{i-1}$ ã«ããé¸ã³æ¹ã¨åããã
- ãã®é¸ã³æ¹ã¯ã$j-w_{i-1}\ge 0$ ã®å ´åã®ã¿å¯è½
- ãããã¯ã$j'< 0$ ã®ã¨ã $\dp[i][j']=\emptyset$ ã¨è¦ã¦ããã
ã®ããããã¨ãªãã¾ãã$i$ åç®ã®ååã®æç¡ãç°ãªãã®ã§ãä¸è¨ã®äºã¤ã«éè¤ã¯ããã¾ãããï¼æ¼ãããªããã¨ã¯ã©ã示ãï¼ æ¼ãã¦ããé¸ã³æ¹ã®åå¨ãä»®å®ãã¦èçæ³ï¼ï¼
ãã¦ãåè 㯠$\dp[i-1][j]$ ã¨è¡¨ãã¾ãã å¾è ã¯ã$$\{S\cup \{(i-1, w_{i-1}, v_{i-1})\}\mid S\in\dp[i-1][j-w_{i-1}]\}$$ ã¨è¡¨ãã¾ããå¼ããã¡ããã¡ããã¦ãã¾ã£ã¦ãã¾ããã$\dp[i-1][j-w_{i-1}]$ ã«ããé¸ã³æ¹åã ã«ã¤ãã¦ãåå $i-1$ ã追å ããé¸ã³æ¹ãä½ã£ã¦ããã¨ããã ãã§ãã
ã¨ãããã¨ã§ã$\dp[i][j]$ ã $\dp[i-1][j']$ ($j'< j$) ããæ±ããããã¨ããã£ãã®ã§ã$i$ ã®æé ã« $\dp[i][j]$ ãæ±ãã¦ãããã¨ãã§ãããã§ãï¼$j$ ã«é¢ãã¦ã¯é©å½ãªé çªã§ããããã§ãã並ååãããã¨ãå¯è½ããã§ããï¼ã ãã®ã¨ãã«ã$\dp[i][j]$ ã $\dp[i'][j']$ ($i'< i$ or $j' < j$) ã§ã¯ãã¾ã表ããªããã¨ãªã£ãå ´åã¯ã$\dp[i][j][k]$ ã®ããã«å¤æ°ãå¢ãããããâå é $i$ åâ ã§ã¯ãªã DP ãèãããããå¿ è¦ãããããã§ãã
å ·ä½çãªæ°å¤ã§ã®ä¾
é©å½ãªä¾ãæãã¦èãã¦ã¿ã¾ãããã ååå ¨ä½ã®éåã¨ãã¦ããã¨ãã° $\{(0, 2, 5), (1, 5, 4), (2, 3, 3), (3, 1, 6)\}$ ãèãã¾ããéãã $5$ 以ä¸ã«ãªããã®ãã¹ã¦ããåè¿°ã® DP ã«å¾ã£ã¦æ±ãã¦ã¿ã¾ãã
$$ \begin{aligned} \dp[0][0] &= \{\emptyset\}, \\ \dp[0][1] &= \emptyset, \\ \dp[0][2] &= \emptyset, \\ \dp[0][3] &= \emptyset, \\ \dp[0][4] &= \emptyset, \\ \dp[0][5] &= \emptyset, \\ \dp[1][0] &= \dp[0][0] \cup \{S\cup\{(0, 2, 5)\}\mid S\in\dp[0][-2]\} = \{\emptyset\}, \\ \dp[1][1] &= \dp[0][1] \cup \{S\cup\{(0, 2, 5)\}\mid S\in\dp[0][-1]\} = \emptyset, \\ \dp[1][2] &= \dp[0][2] \cup \{S\cup\{(0, 2, 5)\}\mid S\in\dp[0][0]\} \\ &= \emptyset \cup \{\emptyset\cup\{(0, 2, 5)\}\} = \{\{(0, 2, 5)\}\}, \\ \dp[1][3] &= \dp[0][3] \cup \{S\cup\{(0, 2, 5)\}\mid S\in\dp[0][1]\} = \emptyset, \\ \dp[1][4] &= \dp[0][4] \cup \{S\cup\{(0, 2, 5)\}\mid S\in\dp[0][2]\} = \emptyset, \\ \dp[1][5] &= \dp[0][5] \cup \{S\cup\{(0, 2, 5)\}\mid S\in\dp[0][3]\} = \emptyset, \\ \dp[2][0] &= \dp[1][0] \cup \{S\cup\{(1, 5, 4)\}\mid S\in\dp[1][-5]\} = \{\emptyset\}, \\ \dp[2][1] &= \dp[1][1] \cup \{S\cup\{(1, 5, 4)\}\mid S\in\dp[1][-4]\} = \emptyset, \\ \dp[2][2] &= \dp[1][2] \cup \{S\cup\{(1, 5, 4)\}\mid S\in\dp[1][-3]\} = \{\{(0, 2, 5)\}\}, \\ \dp[2][3] &= \dp[1][3] \cup \{S\cup\{(1, 5, 4)\}\mid S\in\dp[1][-2]\} = \emptyset, \\ \dp[2][4] &= \dp[1][4] \cup \{S\cup\{(1, 5, 4)\}\mid S\in\dp[1][-1]\} = \emptyset, \\ \dp[2][5] &= \dp[1][5] \cup \{S\cup\{(1, 5, 4)\}\mid S\in\dp[1][0]\} \\ &= \emptyset \cup \{\emptyset\cup\{(1, 5, 4)\}\} = \{\{(1, 5, 4)\}\}, \\ \dp[3][0] &= \dp[2][0] \cup \{S\cup\{(2, 3, 3)\}\mid S\in\dp[2][-3]\} = \{\emptyset\}, \\ \dp[3][1] &= \dp[2][1] \cup \{S\cup\{(2, 3, 3)\}\mid S\in\dp[2][-2]\} = \emptyset, \\ \dp[3][2] &= \dp[2][2] \cup \{S\cup\{(2, 3, 3)\}\mid S\in\dp[2][-1]\} = \{\{(0, 2, 5)\}\}, \\ \dp[3][3] &= \dp[2][3] \cup \{S\cup\{(2, 3, 3)\}\mid S\in\dp[2][0]\}, \\ &= \emptyset \cup \{\emptyset\cup\{(2, 3, 3)\}\} = \{\{(2, 3, 3)\}\} \\ \dp[3][4] &= \dp[2][4] \cup \{S\cup\{(2, 3, 3)\}\mid S\in\dp[2][1]\} = \emptyset, \\ \dp[3][5] &= \dp[2][5] \cup \{S\cup\{(2, 3, 3)\}\mid S\in\dp[2][2]\} \\ &= \{\{(1, 5, 4)\}\} \cup \{\{(0, 2, 5)\}\cup\{(2, 3, 3)\}\} \\ &= \{\{(1, 5, 4)\}, \{(0, 2, 5), (2, 3, 3)\}\}, \\ \dp[4][0] &= \dp[3][0] \cup \{S\cup\{(3, 1, 6)\}\mid S\in\dp[3][-1]\} = \{\emptyset\}, \\ \dp[4][1] &= \dp[3][1] \cup \{S\cup\{(3, 1, 6)\}\mid S\in\dp[3][0]\} \\ &= \emptyset \cup \{\emptyset\cup\{(3, 1, 6)\}\} = \{\{(3, 1, 6)\}\}, \\ \dp[4][2] &= \dp[3][2] \cup \{S\cup\{(3, 1, 6)\}\mid S\in\dp[3][1]\} = \{\{(0, 2, 5)\}\}, \\ \dp[4][3] &= \dp[3][3] \cup \{S\cup\{(3, 1, 6)\}\mid S\in\dp[3][2]\} \\ &= \{\{(2, 3, 3)\}\} \cup \{\{(0, 2, 5)\}\cup\{(3, 1, 6)\}\} \\ &= \{\{(2, 3, 3)\}, \{(0, 2, 5), (3, 1, 6)\}\}, \\ \dp[4][4] &= \dp[3][4] \cup \{S\cup\{(3, 1, 6)\}\mid S\in\dp[3][3]\} \\ &= \emptyset \cup \{\{(2, 3, 3)\}\cup\{(3, 1, 6)\}\} \\ &= \{\{(2, 3, 3), (3, 1, 6)\}\}, \\ \dp[4][5] &= \dp[3][5] \cup \{S\cup\{(3, 1, 6)\}\mid S\in\dp[3][4]\} \\ &= \{\{(1, 5, 4)\}, \{(0, 2, 5), (2, 3, 3)\}\}. \end{aligned} $$
以ä¸ãããï¼ååå ¨ä½ãèãã¦ï¼éããã¡ããã© $j$ ($j\le 5$) ã«ãªããããªé¸ã³æ¹ã¯ã
- $j = 0$ ã®å ´åã$\dp[4][0] = \{\emptyset\}$
- $j = 1$ ã®å ´åã$\dp[4][1] = \{\{(3, 1, 6)\}\}$
- $j = 2$ ã®å ´åã$\dp[4][2] = \{\{(0, 2, 5)\}\}$
- $j = 3$ ã®å ´åã$\dp[4][3] = \{\{(2, 3, 3)\}, \{(0, 2, 5), (3, 1, 6)\}\}$
- $j = 4$ ã®å ´åã$\dp[4][4] = \{\{(2, 3, 3), (3, 1, 6)\}\}$
- $j = 5$ ã®å ´åã$\dp[4][5] = \{\{(1, 5, 4)\}, \{(0, 2, 5), (2, 3, 3)\}\}$
ã¨ãããã¾ãã
æç´ãª DP ããç¡é§ãæ¸ãã
ä¸è¨ã® DP ã§ã¯ãçµå±ã¯é¸ã³æ¹ãé½ã«è¨ç®ãã¦ãããããææªã®å ´åã¯ææ°åã®å¤ãæã¤å¿ è¦ãåºã¦ãã¾ãã ãã¨ãã°ãéã $100$ 以ä¸ã®é¸ã³æ¹ãåæãããã¨ãã¦åååã®éããå ¨é¨ $1$ ã ã£ãã $2^{100}$ åã®é¸ã³æ¹ãæã¤å¿ è¦ãããã¾ããã
ãã¦ãå ¸åçãªä¾ã¨ãã¦ãå é $i$ åã®ååã使ã£ã¦éããã¡ããã© $j$ ã«ããã¨ãã®ä¾¡å¤ã®æ大å¤ãèãã¾ãã ããã¯ãå ã»ã©èãã $\dp[i][j]$ ãç¨ã㦠$\gdef\placeholder{\bullet}$ $$ \max\,\left\{\sum_{(\placeholder, \placeholder, v)\in S} v \Biggm| S \in \dp[i][j]\right\} $$ ã®ããã«æ¸ãã¾ã*1ã
ã¾ãã$i$ åç®ã®ååã使ã使ããªãã®åå²ãæ¸ãã¨ã $$ \max\,\left(\left\{\sum_{(\placeholder, \placeholder, v)\in S} v \Biggm| S \in \dp[i-1][j]\right\} \cup \left\{\sum_{(\placeholder, \placeholder, v)\in S} v \Biggm| S \in \{S'\cup \{(i-1, w_{i-1}, v_{i-1})\}\mid S'\in\dp[i-1][j-w_{i-1}]\}\right\}\right) $$ ã¨ãªãã¾ãï¼é·ã...ï¼ã$\max A\cup B = \max\,\{\max A, \max B\}$ ãªã®ã§ãåã èãã¾ãã
è¤éãªå½¢ããã¦ããå¾è ã«ã¤ãã¦èãã¾ãï¼åè ã¯ãã§ã«åãå½¢ã«ãªã£ã¦ããã®ã§å¤§ä¸å¤«ã$(i, j) \gets (i-1, j)$ ã§ç½®ãæããã ãã®å¼ã¨ãããã¨ï¼ã $$ \begin{aligned} &\phantom{{}={}} \max\,\left\{\sum_{(\placeholder, \placeholder, v)\in S} v \Biggm| S \in \{S'\cup \{(i-1, w_{i-1}, v_{i-1})\}\mid S'\in\dp[i-1][j-w_{i-1}]\}\right\} \\ &= \max\,\left\{\sum_{(\placeholder, \placeholder, v)\in S\cup\{(i-1, w_{i-1}, v_{i-1})\}} v \Biggm| S \in \dp[i-1][j-w_{i-1}]\right\} \\ &= \max\,\left\{\left(\sum_{(\placeholder, \placeholder, v)\in S} v\right)+v_{i-1} \Biggm| S \in \dp[i-1][j-w_{i-1}]\right\} \\ &= \max\,\left\{\sum_{(\placeholder, \placeholder, v)\in S} v \Biggm| S \in \dp[i-1][j-w_{i-1}]\right\}+v_{i-1} \\ \end{aligned} $$
ãã® $\max$ ã®é¨åãè¦ãã¨ãå ã»ã© $\dp[i][j]$ ããçããæ±ããé¨åã®å¼ã¨åãå½¢ããã¦ãããã¨ããããã¾ãã ãã£ã¦ãæ¹ã㦠$$ \dp'[i][j] \triangleq \max\,\left\{\sum_{(\placeholder, \placeholder, v)\in S} v \Biggm| S \in \dp[i][j]\right\} $$ ã¨ããã¨ã$i\gt 0$ ã«å¯¾ã㦠$$ \dp'[i][j] = \max\, \{\dp'[i-1][j], \dp'[i][j-w_{i-1}]+v_{i-1}\} $$ ã¨æ¸ãããã¨ããããã¾ãã
ãã¼ã¹ã±ã¼ã¹ã«ã¤ãã¦ãè¨ç®ãã¦ããã¾ãããã $$ \begin{aligned} \dp'[0][0] &= \max\,\left\{\sum_{(\placeholder, \placeholder, v)\in S} v \Biggm| S \in \{\emptyset\}\right\} \\ &= \sum_{(\placeholder, \placeholder, v)\in \emptyset} v = 0, \\ \dp'[0][j] &= \max\,\left\{\sum_{(\placeholder, \placeholder, v)\in S} v \Biggm| S \in \emptyset\right\} \\ &= \max \emptyset = -\infty, \qquad \text{for }j\gt 0. \end{aligned} $$
ãã£ã¦ã価å¤ã®æ大åããããã ãã§ããã°ãé¸ã³æ¹å ¨ä½ãä¿æãç¶ãããã¨ãªããå $\dp'[\placeholder][\placeholder]$ ãã¨ã«å¤ä¸ã¤ã§æ¸ãããã«ãªãã¾ããã
- $\dp'[0][0] = 0$
- $\dp'[0][j] = -\infty$ for $j \ne 0$
- $\dp'[i][j] = -\infty$ for $j < 0$
- $\dp'[i][j] = \max\,\{\dp'[i-1][j], \dp'[i-1][j-w_{i-1}]+v_{i-1}\}$ for $i\gt 0$
å®è£ ã®éã¯ã$-\infty$ ã¨ãªããããªã¨ã³ããªã¯ããããæããã«ãã¾ããã£ã¦ã大ä¸å¤«ã§ããè² ã®æ·»åãããæãã«æ±ããè¨èªã§ããã°ããããå©ç¨ãã¦ãããã§ãããã ã¾ãã$-\infty$ ã $-2^{62}$ ã®ãããªçµ¶å¯¾å¤ã®å¤§ããè² ã®æ°ã§ä»£ç¨ããå ´åã¯ãæçµçãªçãã $-\infty$ ãã©ããã®å¤å®ã®éã«ãã°ãããªãããã«æ³¨æãã¾ãããï¼$-2^{62}+v_{i-1} \gt -2^{62}$ ãªã©ã¨ãªãã$-\infty$ ã«æå¾ ãã¦ããæ§è³ªã¨ç°ãªã£ããããããï¼ã
ãããã¡
ãããªãæ大å¤ã¨ããèã㦠DP ãããã¨ããã«ãæã«èæ ®ããã¦ããã±ã¼ã¹å ¨ä½ãã¡ããã¨æèãã¦ã¿ãã¨ãç´å¾ããããï¼ãããã¯ãå¤ãªèæ ®æ¼ãããªãããï¼ã®ã§ã¯ãªãããªã¨æãã¾ããã ä»ã«ããæ大åã§ã¯ãªãæ°ãä¸ãã¸ã®å¿ç¨ï¼éããã¡ããã© $j$ ã«ãªãé¸ã³æ¹ã®éãæ°ã¯ï¼ éããã¡ããã© $j$ ã«ãªãã¨ãã®ä¾¡å¤ã®ç·åã¯ï¼ï¼ãã¤ã¡ã¼ã¸ãããããªãããã§ãã
ã¾ãã$\dp'[i][j]$ ãæ±ããéã«ã$\dp[i][j]$ ã使ã£ãå®ç¾©å¼ã¨åãå½¢ã®å¼ãåºã¦ãããã¨ãæèãã¾ãããããããæèãããã¨ã大äºã§ãã ãå é $i$ åãè¦ãã¨ãã®ä½ã ã®å¤ãããå é $i-1$ åãè¦ãã¨ãã®ä½ã ã®å¤ãããç°¡åã«è¨ç®ã§ãããã¨ã大äºãªã®ã§ãããããããã«ã§ãã DP ã®å®ç¾©ãèããããããããå¤ã¨è¦åãããããªå¼å¤å½¢ããããã¨ãéè¦ã§ãã
å é $i$ åãè¦ã¦ã¿ãã®ã¯ãããä¸çªãã¼ã·ãã¯ã ããã§ããã¨ãããããã®æ¹éã§ãã¾ããããªããèãã¦ã¿ã¦ãã ããããªãå¥ã®ããæ¹ãæ¤è¨ããã¨ãã§ããã¨æãã¾ãã ãã¡ããããã以å¤ã«ãå ¸åãã¿ã¼ã³ã®ãããªãã®ã¯ãã£ã¦ã
- æ¨æ§é ã®èãã¼ããèªæãªã±ã¼ã¹ãªã®ã§ãããããæ ¹ã«åãã£ã¦æ±ããï¼æ¨ DPï¼
- å¹ 1 ã®åºéãèªæãªã±ã¼ã¹ãªã®ã§ããããã大ããªåºéã®å ´åãæ±ããï¼åºé DPï¼
- ã´ã¼ã«ã®ç¶æ ãèªæãªã±ã¼ã¹ãªã®ã§ãããããã¹ã¿ã¼ãã«åãã£ã¦æ±ããï¼æå¾ å¤ãã²ã¼ã ãªã©ï¼
- 空éåãèªæãªã±ã¼ã¹ãªã®ã§ãããããå ¨ä½éåã«åãã£ã¦æ±ããï¼bit DPï¼
- DAG ã«ãããå ¥æ¬¡æ° 0 ã®ãã¼ããèªæãªã±ã¼ã¹ãªã®ã§ãããããåãã¼ãã§ã®å¤ãæ±ããï¼ååããï¼ï¼
ãªã©ã§ãããDP ã¨è¨ãã°å é $i$ åãè¦ããã§ã¯ãªãã¦ãDP ã¨è¨ãã°èªæãªã±ã¼ã¹ãããã¨ããã®ãéè¦ã§ãã èªæãªã±ã¼ã¹ããå§ãã¦ãéèªæãªã±ã¼ã¹ã§ã¯åãå½¢å¼ã®ããèªæãªã±ã¼ã¹ã«å¸°çããã¾ãããï¼èªæãªã±ã¼ã¹ããé ã ã«æ±ãã¦ããã®ã§ï¼ã
ããã
ä»åã¯ããããµãã¯åé¡ã® DP ãä¾ã«æãã¾ããããä»ã®å ¸åçãªæé©åã»æ°ãä¸ãã® DP ã§ãã£ã¦ããåãããã«ãæã«èãã¦ããã±ã¼ã¹ãã¡ããã¨æèãããã¨ããã®ã¯å¤§äºãªãã¨ã ã¨æãã¾ãã æ £ãã¦ããã°ç¡æèã«ã§ããããã«ãªãã¨æãã®ã§ãåãã¯æèãã¦ã¿ãã¨ããã¨æãã¾ãã
人ã«ãã£ã¦ãã£ããããã¤ã¡ã¼ã¸ã¯ç°ãªããããããªãã§ããããªã«ããããå¾ããã£ããã«ãªãã°ããããã§ãã
*1:$\placeholder$ ã¯ãè¨ç®ã«ä½¿ããªãé¨åãæ示ããªãããã«ãã¦ããã ãã§ãã$(i, w_{i}, v_{i})\in S$ ã¨æ¸ãã¨åé·ãªä¸ã$i$ ããã¶ã£ã¦ç´ãããããªãããã ã£ãã®ã§ã