<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 byRec(string &s1,string &s2,int i,int j){
        if(i>=s1.size() && j>=s2.size()){
            return 0;
        }

        if(i>=s1.size()){
            int ttl=0;
            while(j<s2.size()){
                ttl+=s2[j];
                j++;
            }

            return ttl;
        }

        if(j>=s2.size()){
            int ttl=0;
            while(i<s1.size()){
                ttl+=s1[i];
                i++;
            }

            return ttl;
        }

        if(s1[i]==s2[j]){
            return byRec(s1,s2,i+1,j+1);
        }
        else{
            int op1=s1[i]+byRec(s1,s2,i+1,j);
            int op2=s2[j]+byRec(s1,s2,i,j+1);
            int op3=s1[i]+s2[j]+byRec(s1,s2,i+1,j+1);

            return min(min(op1,op2),op3);
        }
    }

    int byMem(string &s1,string &s2,int i,int j,vector<vector<int>>&dp){
        if(i>=s1.size() && j>=s2.size()){
            return 0;
        }

        if(i>=s1.size()){
            int ttl=0;
            while(j<s2.size()){
                ttl+=s2[j];
                j++;
            }

            return ttl;
        }

        if(j>=s2.size()){
            int ttl=0;
            while(i<s1.size()){
                ttl+=s1[i];
                i++;
            }

            return ttl;
        }

        if(dp[i][j]!=-1) return dp[i][j];

        if(s1[i]==s2[j]){
            return byMem(s1,s2,i+1,j+1,dp);
        }
        else{
            int op1=s1[i]+byMem(s1,s2,i+1,j,dp);
            int op2=s2[j]+byMem(s1,s2,i,j+1,dp);
            // int op3=s1[i]+s2[j]+byMem(s1,s2,i+1,j+1,dp);

            return dp[i][j]=min(op1,op2);
        }
    }

    int byTabu(string &s1,string &s2){
        vector<vector<int>>dp(s1.size()+1,vector<int>(s2.size()+1,-1));
        for(int col=0;col<=s2.size();col++){
            int ttl=0;
            int j=col;

            while(j<s2.size()){
                ttl+=s2[j];
                j++;
            }

            dp[s1.size()][col]=ttl;
        }

        for(int row=0;row<=s1.size();row++){
            int ttl=0;
            int i=row;

            while(i<s1.size()){
                ttl+=s1[i];
                i++;
            }

            dp[row][s2.size()]=ttl;
        }

        // dp[s1.size()][s2.size()]=0;

        for(int i=s1.size()-1;i>=0;i--){
            for(int j=s2.size()-1;j>=0;j--){
                if(s1[i]==s2[j]){
                    dp[i][j]=dp[i+1][j+1];
                }
                else{
                    int op1=s1[i]+dp[i+1][j];
                    int op2=s2[j]+dp[i][j+1];
                    // int op3=s1[i]+s2[j]+byMem(s1,s2,i+1,j+1,dp);

                    dp[i][j]=min(op1,op2);
                }
            }
        }

        return dp[0][0];

    }

    int bySO(string&s1,string&s2){
        vector<int>curr(s2.size()+1,0);
         vector<int>next(s2.size()+1,0);

         for(int col=0;col<=s2.size();col++){
            int ttl=0;
            int j=col;

            while(j<s2.size()){
                ttl+=s2[j];
                j++;
            }

            next[col]=ttl;
        }

         for(int i=s1.size()-1;i>=0;i--){
            int ttl=0;
            int row=i;

            while(row<s1.size()){
                ttl+=s1[row];
                row++;
            }

            curr[s2.size()]=ttl;


            for(int j=s2.size()-1;j>=0;j--){
                if(s1[i]==s2[j]){
                    curr[j]=next[j+1];
                }
                else{
                    int op1=s1[i]+next[j];
                    int op2=s2[j]+curr[j+1];
                    // int op3=s1[i]+s2[j]+byMem(s1,s2,i+1,j+1,dp);

                    curr[j]=min(op1,op2);
                }
            }

            next=curr;
        }

        return next[0];
    }
    int minimumDeleteSum(string s1, string s2) {
        // return byRec(s1,s2,0,0);

        // vector<vector<int>>dp(s1.size()+1,vector<int>(s2.size()+1,-1));
        // return byMem(s1,s2,0,0,dp);

        // return byTabu(s1,s2);

        return bySO(s1,s2);
    }
};
8300