<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>1D DP on Jeanphilo Blog</title><link>https://shio-chan-dev.github.io/jeanblog/tags/1d-dp/</link><description>Recent content in 1D DP on Jeanphilo Blog</description><generator>Hugo -- 0.161.1</generator><language>en-us</language><lastBuildDate>Sun, 03 May 2026 14:33:39 +0800</lastBuildDate><atom:link href="https://shio-chan-dev.github.io/jeanblog/tags/1d-dp/index.xml" rel="self" type="application/rss+xml"/><item><title>LeetCode 198: House Robber, Deriving 1D DP from Rob or Skip</title><link>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/hot100/198-house-robber/</link><pubDate>Sun, 03 May 2026 14:33:39 +0800</pubDate><guid>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/hot100/198-house-robber/</guid><description>&lt;h2 id="problem"&gt;Problem&lt;/h2&gt;
&lt;h3 id="input-and-output"&gt;Input and Output&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Input: an integer array &lt;code&gt;nums&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;nums[i]&lt;/code&gt; is the money in the &lt;code&gt;i&lt;/code&gt;-th house&lt;/li&gt;
&lt;li&gt;Adjacent houses cannot both be robbed&lt;/li&gt;
&lt;li&gt;Output: return the maximum amount of money that can be robbed&lt;/li&gt;
&lt;li&gt;Constraints: &lt;code&gt;1 &amp;lt;= nums.length &amp;lt;= 100&lt;/code&gt;, &lt;code&gt;0 &amp;lt;= nums[i] &amp;lt;= 400&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="examples"&gt;Examples&lt;/h3&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Input: nums = [1,2,3,1]
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Output: 4
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Explanation: rob indices 0 and 2, for 1 + 3 = 4
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Input: nums = [2,7,9,3,1]
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Output: 12
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Explanation: rob indices 0, 2, and 4, for 2 + 9 + 1 = 12
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This article uses Python only and derives 1D DP from the conflict between two choices.&lt;/p&gt;</description></item><item><title>LeetCode 70: Climbing Stairs, Deriving 1D DP from dp[i]</title><link>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/70-climbing-stairs/</link><pubDate>Sun, 03 May 2026 14:33:39 +0800</pubDate><guid>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/70-climbing-stairs/</guid><description>&lt;h2 id="problem"&gt;Problem&lt;/h2&gt;
&lt;h3 id="input-and-output"&gt;Input and Output&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Input: an integer &lt;code&gt;n&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Meaning: climb to the top of the &lt;code&gt;n&lt;/code&gt;-step staircase&lt;/li&gt;
&lt;li&gt;Each move can climb &lt;code&gt;1&lt;/code&gt; or &lt;code&gt;2&lt;/code&gt; steps&lt;/li&gt;
&lt;li&gt;Output: return the number of distinct ways to reach the top&lt;/li&gt;
&lt;li&gt;Constraints: &lt;code&gt;1 &amp;lt;= n &amp;lt;= 45&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="examples"&gt;Examples&lt;/h3&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Input: n = 2
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Output: 2
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Explanation: 1+1, 2
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Input: n = 3
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Output: 3
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Explanation: 1+1+1, 1+2, 2+1
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This article uses Python only and derives the final solution step by step from the meaning of &lt;code&gt;dp[i]&lt;/code&gt;.&lt;/p&gt;</description></item><item><title>LeetCode 746: Min Cost Climbing Stairs, Deriving DP from the Top Position</title><link>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/746-min-cost-climbing-stairs/</link><pubDate>Sun, 03 May 2026 14:33:39 +0800</pubDate><guid>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/746-min-cost-climbing-stairs/</guid><description>&lt;h2 id="problem"&gt;Problem&lt;/h2&gt;
&lt;h3 id="input-and-output"&gt;Input and Output&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Input: an integer array &lt;code&gt;cost&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;cost[i]&lt;/code&gt; is the cost of stepping on stair &lt;code&gt;i&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Each move can climb &lt;code&gt;1&lt;/code&gt; or &lt;code&gt;2&lt;/code&gt; steps&lt;/li&gt;
&lt;li&gt;You may start from index &lt;code&gt;0&lt;/code&gt; or index &lt;code&gt;1&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Output: return the minimum cost to reach the top&lt;/li&gt;
&lt;li&gt;Constraints: &lt;code&gt;2 &amp;lt;= cost.length &amp;lt;= 1000&lt;/code&gt;, &lt;code&gt;0 &amp;lt;= cost[i] &amp;lt;= 999&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="examples"&gt;Examples&lt;/h3&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Input: cost = [10,15,20]
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Output: 15
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Explanation: start from index 1, pay 15, then reach the top directly
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Input: cost = [1,100,1,1,1,100,1,1,100,1]
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Output: 6
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id="start-from-the-top-position-of-101520"&gt;Start from the Top Position of [10,15,20]&lt;/h2&gt;
&lt;p&gt;Look at the small example:&lt;/p&gt;</description></item></channel></rss>