<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="th">
	<id>http://158.108.32.49/wiki/index.php?action=history&amp;feed=atom&amp;title=418531_%E0%B8%A0%E0%B8%B2%E0%B8%84%E0%B8%95%E0%B9%89%E0%B8%99_2552%2F%E0%B9%82%E0%B8%88%E0%B8%97%E0%B8%A2%E0%B9%8C%E0%B8%9B%E0%B8%B1%E0%B8%8D%E0%B8%AB%E0%B8%B2%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B9%82%E0%B8%9B%E0%B8%A3%E0%B9%81%E0%B8%81%E0%B8%A3%E0%B8%A1%E0%B8%9E%E0%B8%A5%E0%B8%A7%E0%B8%B1%E0%B8%95_I%2F%E0%B9%80%E0%B8%89%E0%B8%A5%E0%B8%A2%E0%B8%82%E0%B9%89%E0%B8%AD_1</id>
	<title>418531 ภาคต้น 2552/โจทย์ปัญหาการโปรแกรมพลวัต I/เฉลยข้อ 1 - ประวัติรุ่นแก้ไข</title>
	<link rel="self" type="application/atom+xml" href="http://158.108.32.49/wiki/index.php?action=history&amp;feed=atom&amp;title=418531_%E0%B8%A0%E0%B8%B2%E0%B8%84%E0%B8%95%E0%B9%89%E0%B8%99_2552%2F%E0%B9%82%E0%B8%88%E0%B8%97%E0%B8%A2%E0%B9%8C%E0%B8%9B%E0%B8%B1%E0%B8%8D%E0%B8%AB%E0%B8%B2%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B9%82%E0%B8%9B%E0%B8%A3%E0%B9%81%E0%B8%81%E0%B8%A3%E0%B8%A1%E0%B8%9E%E0%B8%A5%E0%B8%A7%E0%B8%B1%E0%B8%95_I%2F%E0%B9%80%E0%B8%89%E0%B8%A5%E0%B8%A2%E0%B8%82%E0%B9%89%E0%B8%AD_1"/>
	<link rel="alternate" type="text/html" href="http://158.108.32.49/wiki/index.php?title=418531_%E0%B8%A0%E0%B8%B2%E0%B8%84%E0%B8%95%E0%B9%89%E0%B8%99_2552/%E0%B9%82%E0%B8%88%E0%B8%97%E0%B8%A2%E0%B9%8C%E0%B8%9B%E0%B8%B1%E0%B8%8D%E0%B8%AB%E0%B8%B2%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B9%82%E0%B8%9B%E0%B8%A3%E0%B9%81%E0%B8%81%E0%B8%A3%E0%B8%A1%E0%B8%9E%E0%B8%A5%E0%B8%A7%E0%B8%B1%E0%B8%95_I/%E0%B9%80%E0%B8%89%E0%B8%A5%E0%B8%A2%E0%B8%82%E0%B9%89%E0%B8%AD_1&amp;action=history"/>
	<updated>2026-05-07T01:36:52Z</updated>
	<subtitle>ประวัติรุ่นแก้ไขของหน้านี้ในวิกิ</subtitle>
	<generator>MediaWiki 1.33.1</generator>
	<entry>
		<id>http://158.108.32.49/wiki/index.php?title=418531_%E0%B8%A0%E0%B8%B2%E0%B8%84%E0%B8%95%E0%B9%89%E0%B8%99_2552/%E0%B9%82%E0%B8%88%E0%B8%97%E0%B8%A2%E0%B9%8C%E0%B8%9B%E0%B8%B1%E0%B8%8D%E0%B8%AB%E0%B8%B2%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B9%82%E0%B8%9B%E0%B8%A3%E0%B9%81%E0%B8%81%E0%B8%A3%E0%B8%A1%E0%B8%9E%E0%B8%A5%E0%B8%A7%E0%B8%B1%E0%B8%95_I/%E0%B9%80%E0%B8%89%E0%B8%A5%E0%B8%A2%E0%B8%82%E0%B9%89%E0%B8%AD_1&amp;diff=7701&amp;oldid=prev</id>
		<title>Cardcaptor: /* นิยามค่า OPT \, */</title>
		<link rel="alternate" type="text/html" href="http://158.108.32.49/wiki/index.php?title=418531_%E0%B8%A0%E0%B8%B2%E0%B8%84%E0%B8%95%E0%B9%89%E0%B8%99_2552/%E0%B9%82%E0%B8%88%E0%B8%97%E0%B8%A2%E0%B9%8C%E0%B8%9B%E0%B8%B1%E0%B8%8D%E0%B8%AB%E0%B8%B2%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B9%82%E0%B8%9B%E0%B8%A3%E0%B9%81%E0%B8%81%E0%B8%A3%E0%B8%A1%E0%B8%9E%E0%B8%A5%E0%B8%A7%E0%B8%B1%E0%B8%95_I/%E0%B9%80%E0%B8%89%E0%B8%A5%E0%B8%A2%E0%B8%82%E0%B9%89%E0%B8%AD_1&amp;diff=7701&amp;oldid=prev"/>
		<updated>2009-10-04T15:24:42Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;นิยามค่า OPT \,&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;th&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;←รุ่นแก้ไขก่อนหน้า&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;รุ่นแก้ไขเมื่อ 15:24, 4 ตุลาคม 2552&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l8&quot; &gt;แถว 8:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;แถว 8:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;(Induction Case) สมมติว่า &amp;lt;math&amp;gt;OPT(i) \,&amp;lt;/math&amp;gt; มีค่าเท่ากับผลรวมที่มากที่สุดของลำดับย่ยอที่ติดกันที่มีช่องสุดท้ายอยู่ที่ช่อง &amp;lt;math&amp;gt;a[i] \,&amp;lt;/math&amp;gt; สำหรับ &amp;lt;math&amp;gt;i \geq 1 \,&amp;lt;/math&amp;gt; บางค่า พิจารณาลำดับย่อยที่มีผลบวกมากที่สุดจบที่ช่อง &amp;lt;math&amp;gt;a[i+1] \,&amp;lt;/math&amp;gt; เราจะได้ว่ามีความเป็นไปได้สองกรณีด้วยกัน&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;(Induction Case) สมมติว่า &amp;lt;math&amp;gt;OPT(i) \,&amp;lt;/math&amp;gt; มีค่าเท่ากับผลรวมที่มากที่สุดของลำดับย่ยอที่ติดกันที่มีช่องสุดท้ายอยู่ที่ช่อง &amp;lt;math&amp;gt;a[i] \,&amp;lt;/math&amp;gt; สำหรับ &amp;lt;math&amp;gt;i \geq 1 \,&amp;lt;/math&amp;gt; บางค่า พิจารณาลำดับย่อยที่มีผลบวกมากที่สุดจบที่ช่อง &amp;lt;math&amp;gt;a[i+1] \,&amp;lt;/math&amp;gt; เราจะได้ว่ามีความเป็นไปได้สองกรณีด้วยกัน&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# ลำดับย่อยนั้นเริ่มต้นที่ช่อง &amp;lt;math&amp;gt;a[i+1] \,&amp;lt;/math&amp;gt; ด้วย ในกรณีนี้ &amp;lt;math&amp;gt;OPT(i+1) = a[i+1] \,&amp;lt;/math&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# ลำดับย่อยนั้นเริ่มต้นที่ช่อง &amp;lt;math&amp;gt;a[i+1] \,&amp;lt;/math&amp;gt; ด้วย ในกรณีนี้ &amp;lt;math&amp;gt;OPT(i+1) = a[i+1] \,&amp;lt;/math&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;ลำดับย่อยนั้นไม่ได้เริ่มต้อนที่ช่อง &lt;/del&gt;&amp;lt;math&amp;gt;a[i+1] \,&amp;lt;/math&amp;gt; ในกรณีนี้เราจะได้ว่าลำดับย่อยนั้นเกิดจากการนำเอาลำดับย่อยที่จบที่ช่อง &amp;lt;math&amp;gt;a[i] \,&amp;lt;/math&amp;gt; มาต่อกับช่อง &amp;lt;math&amp;gt;a[i+1] \,&amp;lt;/math&amp;gt; ฉะนั้นผลรวมที่มากที่สุดของลำดับย่อยนี้คือ &amp;lt;math&amp;gt;OPT(i) + a[i+1] \,&amp;lt;/math&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;ลำดับย่อยนั้นไม่ได้เริ่มต้นที่ช่อง &lt;/ins&gt;&amp;lt;math&amp;gt;a[i+1] \,&amp;lt;/math&amp;gt; ในกรณีนี้เราจะได้ว่าลำดับย่อยนั้นเกิดจากการนำเอาลำดับย่อยที่จบที่ช่อง &amp;lt;math&amp;gt;a[i] \,&amp;lt;/math&amp;gt; มาต่อกับช่อง &amp;lt;math&amp;gt;a[i+1] \,&amp;lt;/math&amp;gt; ฉะนั้นผลรวมที่มากที่สุดของลำดับย่อยนี้คือ &amp;lt;math&amp;gt;OPT(i) + a[i+1] \,&amp;lt;/math&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;เมื่อรวมสองกรณีข้างบนเข้าด้วยกัน เราจะได้ว่า &amp;lt;math&amp;gt;OPT(i+1) = \max( a[i+1], OPT(i) + a[i+1] ) \,&amp;lt;/math&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;เมื่อรวมสองกรณีข้างบนเข้าด้วยกัน เราจะได้ว่า &amp;lt;math&amp;gt;OPT(i+1) = \max( a[i+1], OPT(i) + a[i+1] ) \,&amp;lt;/math&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Cardcaptor</name></author>
		
	</entry>
	<entry>
		<id>http://158.108.32.49/wiki/index.php?title=418531_%E0%B8%A0%E0%B8%B2%E0%B8%84%E0%B8%95%E0%B9%89%E0%B8%99_2552/%E0%B9%82%E0%B8%88%E0%B8%97%E0%B8%A2%E0%B9%8C%E0%B8%9B%E0%B8%B1%E0%B8%8D%E0%B8%AB%E0%B8%B2%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B9%82%E0%B8%9B%E0%B8%A3%E0%B9%81%E0%B8%81%E0%B8%A3%E0%B8%A1%E0%B8%9E%E0%B8%A5%E0%B8%A7%E0%B8%B1%E0%B8%95_I/%E0%B9%80%E0%B8%89%E0%B8%A5%E0%B8%A2%E0%B8%82%E0%B9%89%E0%B8%AD_1&amp;diff=7700&amp;oldid=prev</id>
		<title>Cardcaptor: หน้าที่ถูกสร้างด้วย &#039;== นิยามค่า &lt;math&gt;OPT \,&lt;/math&gt; == ให้ &lt;math&gt;OPT(i) \,&lt;/math&gt; มีค่าเท่ากับผลรวมท…&#039;</title>
		<link rel="alternate" type="text/html" href="http://158.108.32.49/wiki/index.php?title=418531_%E0%B8%A0%E0%B8%B2%E0%B8%84%E0%B8%95%E0%B9%89%E0%B8%99_2552/%E0%B9%82%E0%B8%88%E0%B8%97%E0%B8%A2%E0%B9%8C%E0%B8%9B%E0%B8%B1%E0%B8%8D%E0%B8%AB%E0%B8%B2%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B9%82%E0%B8%9B%E0%B8%A3%E0%B9%81%E0%B8%81%E0%B8%A3%E0%B8%A1%E0%B8%9E%E0%B8%A5%E0%B8%A7%E0%B8%B1%E0%B8%95_I/%E0%B9%80%E0%B8%89%E0%B8%A5%E0%B8%A2%E0%B8%82%E0%B9%89%E0%B8%AD_1&amp;diff=7700&amp;oldid=prev"/>
		<updated>2009-10-04T15:23:09Z</updated>

		<summary type="html">&lt;p&gt;หน้าที่ถูกสร้างด้วย &amp;#039;== นิยามค่า &amp;lt;math&amp;gt;OPT \,&amp;lt;/math&amp;gt; == ให้ &amp;lt;math&amp;gt;OPT(i) \,&amp;lt;/math&amp;gt; มีค่าเท่ากับผลรวมท…&amp;#039;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;หน้าใหม่&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== นิยามค่า &amp;lt;math&amp;gt;OPT \,&amp;lt;/math&amp;gt; ==&lt;br /&gt;
ให้ &amp;lt;math&amp;gt;OPT(i) \,&amp;lt;/math&amp;gt; มีค่าเท่ากับผลรวมที่มากที่สุดของลำดับย่อยที่ิคิดกันที่มีช่องสุดท้ายอยู่ที่ช่อง &amp;lt;math&amp;gt;a[i] \,&amp;lt;/math&amp;gt; เราจะได้ว่า&lt;br /&gt;
: &amp;lt;math&amp;gt;OPT(i) = \begin{cases} a[1] &amp;amp; i = 1 \\ \max(a[i], OPT(i-1)+a[i]) &amp;amp; i &amp;gt; 1 \end{cases} \,&amp;lt;/math&amp;gt;&lt;br /&gt;
เราสามารถพิสูจน์ว่าสมการข้่างบนเป็นจริงได้ด้วย induction ดังต่อไปนี้&lt;br /&gt;
&lt;br /&gt;
(Base Case) ในกรณีนี้ &amp;lt;math&amp;gt;i = 1 \,&amp;lt;/math&amp;gt; เราจะได้ว่ามีลำดับย่อยที่ติดกันที่จบที่ช่อง &amp;lt;math&amp;gt;a[1] \,&amp;lt;/math&amp;gt; อยู่เพียงแค่ลำดับย่อยเดียว คือ ลำดับย่อยทีี่มีช่อง &amp;lt;math&amp;gt;a[1] \,&amp;lt;/math&amp;gt; เีพียงช่องเดียว ฉะนั้น &amp;lt;math&amp;gt;OPT(1) = a[1] \,&amp;lt;/math&amp;gt; ตามต้องการ&lt;br /&gt;
&lt;br /&gt;
(Induction Case) สมมติว่า &amp;lt;math&amp;gt;OPT(i) \,&amp;lt;/math&amp;gt; มีค่าเท่ากับผลรวมที่มากที่สุดของลำดับย่ยอที่ติดกันที่มีช่องสุดท้ายอยู่ที่ช่อง &amp;lt;math&amp;gt;a[i] \,&amp;lt;/math&amp;gt; สำหรับ &amp;lt;math&amp;gt;i \geq 1 \,&amp;lt;/math&amp;gt; บางค่า พิจารณาลำดับย่อยที่มีผลบวกมากที่สุดจบที่ช่อง &amp;lt;math&amp;gt;a[i+1] \,&amp;lt;/math&amp;gt; เราจะได้ว่ามีความเป็นไปได้สองกรณีด้วยกัน&lt;br /&gt;
# ลำดับย่อยนั้นเริ่มต้นที่ช่อง &amp;lt;math&amp;gt;a[i+1] \,&amp;lt;/math&amp;gt; ด้วย ในกรณีนี้ &amp;lt;math&amp;gt;OPT(i+1) = a[i+1] \,&amp;lt;/math&amp;gt;&lt;br /&gt;
# ลำดับย่อยนั้นไม่ได้เริ่มต้อนที่ช่อง &amp;lt;math&amp;gt;a[i+1] \,&amp;lt;/math&amp;gt; ในกรณีนี้เราจะได้ว่าลำดับย่อยนั้นเกิดจากการนำเอาลำดับย่อยที่จบที่ช่อง &amp;lt;math&amp;gt;a[i] \,&amp;lt;/math&amp;gt; มาต่อกับช่อง &amp;lt;math&amp;gt;a[i+1] \,&amp;lt;/math&amp;gt; ฉะนั้นผลรวมที่มากที่สุดของลำดับย่อยนี้คือ &amp;lt;math&amp;gt;OPT(i) + a[i+1] \,&amp;lt;/math&amp;gt;&lt;br /&gt;
เมื่อรวมสองกรณีข้างบนเข้าด้วยกัน เราจะได้ว่า &amp;lt;math&amp;gt;OPT(i+1) = \max( a[i+1], OPT(i) + a[i+1] ) \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ดั้งนั้นเราจึงสรุปได้ว่าสมการข้างบนเป็นจริงสำหรับค่า &amp;lt;math&amp;gt;i \,&amp;lt;/math&amp;gt; ทุกค่า&lt;br /&gt;
&lt;br /&gt;
== การคำนวณค่า &amp;lt;math&amp;gt;OPT \,&amp;lt;/math&amp;gt; ==&lt;br /&gt;
เราสามารถคำนวณตาราง &amp;lt;math&amp;gt;M[\cdot] \,&amp;lt;/math&amp;gt; โดยที่ &amp;lt;math&amp;gt;M[i] = OPT(i) \,&amp;lt;/math&amp;gt; ได้ดังต่อไปนี้&lt;br /&gt;
&amp;lt;geshi lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
    M[1] = a[1]&lt;br /&gt;
    for i = 2 to n do&lt;br /&gt;
        M[i] = max(a[i], M[i-1] + a[i])&lt;br /&gt;
&amp;lt;/geshi&amp;gt;&lt;br /&gt;
เห็นได้อย่างชัดเจนว่าอัลกอรืทึมส่วนนี้ทำงานได้ในเวลา &amp;lt;math&amp;gt;O(n) \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== การหาช่วงที่มีผลบวกมากที่สุด ==&lt;br /&gt;
เราสามารถหาตำแหน่งของช่องสุดท้ายของช่วงที่มีผลบวกมากที่สุดได้ด้วยการหาค่า &amp;lt;math&amp;gt;j \,&amp;lt;/math&amp;gt; ที่ทำให้ &amp;lt;math&amp;gt;M[j] \,&amp;lt;/math&amp;gt; มากที่สุด&lt;br /&gt;
&lt;br /&gt;
ที่เหลือคือเราจะต้องหาช่องที่ช่วงที่มีผลบวกมากที่สุดเริ่มต้น เราสามารถทำได้โดย pseudocode ต่อไปนี้&lt;br /&gt;
&amp;lt;geshi lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
    i = j&lt;br /&gt;
    while (M[i] != a[i]) do&lt;br /&gt;
        i = i - 1&lt;br /&gt;
&amp;lt;/geshi&amp;gt;&lt;br /&gt;
ค่า &amp;lt;math&amp;gt;i \,&amp;lt;/math&amp;gt; หลังจากที่ loop ทำงานเสร็จจะมีค่าเท่ากับช่องที่ช่วงที่มีผลบวกมากที่สุดเริ่มต้น&lt;br /&gt;
&lt;br /&gt;
ที่เป็นเช่นนี้เพราะว่า จากสมการข้างบน &amp;lt;math&amp;gt;OPT(i) = a[i] \,&amp;lt;/math&amp;gt; หากช่วงที่จบที่ &amp;lt;math&amp;gt;a[i] \,&amp;lt;/math&amp;gt; นั้นเริ่มต้นจาก &amp;lt;math&amp;gt;a[i] \,&amp;lt;/math&amp;gt; ด้วย มิเช่นนั้น &amp;lt;math&amp;gt;OPT(i) = OPT(i-1) + a[i] \,&amp;lt;/math&amp;gt; ดังนั้นหากเราพบช่วงที่ &amp;lt;math&amp;gt;OPT(i) \neq a[i] \,&amp;lt;/math&amp;gt; แสดงว่าช่วงที่จบที่ &amp;lt;math&amp;gt;a[i] \,&amp;lt;/math&amp;gt; นั้นเกิดจากการเอาช่วงที่จบที่ &amp;lt;math&amp;gt;a[i-1] \,&amp;lt;/math&amp;gt; มาต่อกับช่อง &amp;lt;math&amp;gt;a[i] \,&amp;lt;/math&amp;gt; ดังนั้นเราจึงสามารถหาตำแหน่งเริ่มต้นของช่วงที่จบที่ &amp;lt;math&amp;gt;a[i] \,&amp;lt;/math&amp;gt; ด้วยการไปหาตำแหน่งเริ่มต้นของช่วงที่จบที่ &amp;lt;math&amp;gt;a[i-1] \,&amp;lt;/math&amp;gt; แทน&lt;br /&gt;
&lt;br /&gt;
จาก pseudocode ข้างบน เราได้ว่าเราสามารถหาตำแหน่งสิ้นสุด &amp;lt;math&amp;gt;j \,&amp;lt;/math&amp;gt; ของช่วงได้ในเวลา &amp;lt;math&amp;gt;O(n) \,&amp;lt;/math&amp;gt; และหาตำแหน่งเริ่มต้น &amp;lt;math&amp;gt;i \,&amp;lt;/math&amp;gt; ได้ในเวลา &amp;lt;math&amp;gt;O(n) \,&amp;lt;/math&amp;gt; เช่นกัน ดังนั้นอัลกอริทึมทั้งหมดจึงทำงานได้ในเวลา &amp;lt;math&amp;gt;O(n) \,&amp;lt;/math&amp;gt;&lt;/div&gt;</summary>
		<author><name>Cardcaptor</name></author>
		
	</entry>
</feed>