<p>Given two strings <code>s1</code> and&nbsp;<code>s2</code>, return <em>the lowest <strong>ASCII</strong> sum of deleted characters to make two strings equal</em>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> s1 = &quot;sea&quot;, s2 = &quot;eat&quot;
<strong>Output:</strong> 231
<strong>Explanation:</strong> Deleting &quot;s&quot; from &quot;sea&quot; adds the ASCII value of &quot;s&quot; (115) to the sum.
Deleting &quot;t&quot; from &quot;eat&quot; adds 116 to the sum.
At the end, both strings are equal, and 115 + 116 = 231 is the minimum sum possible to achieve this.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> s1 = &quot;delete&quot;, s2 = &quot;leet&quot;
<strong>Output:</strong> 403
<strong>Explanation:</strong> Deleting &quot;dee&quot; from &quot;delete&quot; to turn the string into &quot;let&quot;,
adds 100[d] + 101[e] + 101[e] to the sum.
Deleting &quot;e&quot; from &quot;leet&quot; adds 101[e] to the sum.
At the end, both strings are equal to &quot;let&quot;, and the answer is 100+101+101+101 = 403.
If instead we turned both strings into &quot;lee&quot; or &quot;eet&quot;, we would get answers of 433 or 417, which are higher.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= s1.length, s2.length &lt;= 1000</code></li>
	<li><code>s1</code> and <code>s2</code> consist of lowercase English letters.</li>
</ul>

class Solution {
public:
    int f(string s1, string s2, int ind1, int ind2, map<int, int>&mpp1, map<int, int>&mpp2){
        //base case
        if(ind1==0){
            return mpp2[ind2-1];
        }
        if(ind2==0){
            return mpp1[ind1-1];
        }
        if(s1[ind1-1]==s2[ind2-1]){
            return f(s1, s2, ind1-1, ind2-1, mpp1, mpp2);
        }
        int skip1=s1[ind1-1]+f(s1, s2, ind1-1, ind2, mpp1, mpp2);
        int skip2=s2[ind2-1]+f(s1, s2, ind1, ind2-1, mpp1, mpp2);
        return min(skip1, skip2);
    }
    int f_T(string s1, string s2, map<int, int>&mpp1, map<int, int>&mpp2){
        vector<vector<int>>dp(s1.size()+1, vector<int>(s2.size()+1, 0));
        for(int i=1; i<=s2.size(); i++){
            dp[0][i]=mpp2[i-1];
        }
        for(int i=1; i<=s1.size(); i++){
            dp[i][0]=mpp1[i-1];
        }

        for(int ind1=1; ind1<=s1.size(); ind1++){
            for(int ind2=1; ind2<=s2.size(); ind2++){
                if(s1[ind1-1]==s2[ind2-1]){
                    dp[ind1][ind2]=dp[ind1-1][ind2-1];
                }
                else{
                    int skip1=s1[ind1-1]+dp[ind1-1][ind2];
                    int skip2=s2[ind2-1]+dp[ind1][ind2-1];
                    dp[ind1][ind2]=min(skip1, skip2);
                }
            }
        }

        return dp[s1.size()][s2.size()];
    }
    int minimumDeleteSum(string s1, string s2) {
        map<int, int> mpp1;
        map<int, int> mpp2;
        int t1=0;
        for(int i=0; i<s1.size(); i++){
            t1+=s1[i];
            mpp1[i]=t1;
        }
        int t2=0;
        for(int i=0; i<s2.size(); i++){
            t2+=s2[i];
            mpp2[i]=t2;
        }
       int ind1=s1.size();
       int ind2=s2.size();
       return f_T(s1, s2, mpp1, mpp2); 
    }
};
20500