<?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>Apsp on Yu-Cheng's Notes</title><link>https://linkingmon.github.io/blog/tags/apsp/</link><description>Recent content in Apsp on Yu-Cheng's Notes</description><generator>Hugo -- 0.166.0</generator><language>en-us</language><lastBuildDate>Fri, 30 Jan 2026 00:00:00 +0000</lastBuildDate><atom:link href="https://linkingmon.github.io/blog/tags/apsp/index.xml" rel="self" type="application/rss+xml"/><item><title>LC 2977 - Minimum Cost to Convert String II</title><link>https://linkingmon.github.io/blog/coding/lc-2977/</link><pubDate>Fri, 30 Jan 2026 00:00:00 +0000</pubDate><guid>https://linkingmon.github.io/blog/coding/lc-2977/</guid><description>&lt;h2 id="approach"&gt;Approach&lt;/h2&gt;
&lt;p&gt;This is a really hardr problem, originally I was thinking that for some string like &lt;code&gt;a..&lt;/code&gt; and &lt;code&gt;b..&lt;/code&gt;, we must find somethiong to replace the first character, but I did not notice that the problme describe that the changing substring cannot be overlap (it can only be seperate or the same range). I originally think that &lt;code&gt;ace&lt;/code&gt; as source and &lt;code&gt;bcd&lt;/code&gt; as target, we might have a cost like &lt;code&gt;ce&lt;/code&gt; to &lt;code&gt;ed&lt;/code&gt; and &lt;code&gt;aed&lt;/code&gt; to &lt;code&gt;bcd&lt;/code&gt;, then we can combine both to transit to the target.&lt;/p&gt;</description></item><item><title>LC 2976 - Minimum Cost to Convert String I</title><link>https://linkingmon.github.io/blog/coding/lc-2976/</link><pubDate>Thu, 29 Jan 2026 00:00:00 +0000</pubDate><guid>https://linkingmon.github.io/blog/coding/lc-2976/</guid><description>&lt;h2 id="approach"&gt;Approach&lt;/h2&gt;
&lt;p&gt;This is likely a APSP (all pair shortest path) problem, and can be done with Floyd-Warshall algorithm. Originally I was using 4-loops to check if the dist matrix is converging, but actually the algorithm only need 3 loops with &lt;code&gt;k,i,j&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;I also spend some time to review the floyd warshell algorithm. This is true due to the DP property. the original cost can be formed into a matrix &lt;code&gt;dist_0&lt;/code&gt;, and when we construct &lt;code&gt;dist_1&lt;/code&gt;, we iterate thorugh &lt;code&gt;k=1&lt;/code&gt; meaning that we allow &lt;code&gt;1&lt;/code&gt; to be in the shortest path. When doing &lt;code&gt;k=2&lt;/code&gt;, we allow &lt;code&gt;2,1&lt;/code&gt; to be in the shortest path since we combine the solution from &lt;code&gt;dist_1&lt;/code&gt;, and is currently looking into solution &lt;code&gt;2&lt;/code&gt;.&lt;/p&gt;</description></item></channel></rss>