<p>Given a string <code>num</code> that contains only digits and an integer <code>target</code>, return <em><strong>all possibilities</strong> to insert the binary operators </em><code>&#39;+&#39;</code><em>, </em><code>&#39;-&#39;</code><em>, and/or </em><code>&#39;*&#39;</code><em> between the digits of </em><code>num</code><em> so that the resultant expression evaluates to the </em><code>target</code><em> value</em>.</p>

<p>Note that operands in the returned expressions <strong>should not</strong> contain leading zeros.</p>

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

<pre>
<strong>Input:</strong> num = &quot;123&quot;, target = 6
<strong>Output:</strong> [&quot;1*2*3&quot;,&quot;1+2+3&quot;]
<strong>Explanation:</strong> Both &quot;1*2*3&quot; and &quot;1+2+3&quot; evaluate to 6.
</pre>

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

<pre>
<strong>Input:</strong> num = &quot;232&quot;, target = 8
<strong>Output:</strong> [&quot;2*3+2&quot;,&quot;2+3*2&quot;]
<strong>Explanation:</strong> Both &quot;2*3+2&quot; and &quot;2+3*2&quot; evaluate to 8.
</pre>

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

<pre>
<strong>Input:</strong> num = &quot;3456237490&quot;, target = 9191
<strong>Output:</strong> []
<strong>Explanation:</strong> There are no expressions that can be created from &quot;3456237490&quot; to evaluate to 9191.
</pre>

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

<ul>
	<li><code>1 &lt;= num.length &lt;= 10</code></li>
	<li><code>num</code> consists of only digits.</li>
	<li><code>-2<sup>31</sup> &lt;= target &lt;= 2<sup>31</sup> - 1</code></li>
</ul>

class Solution:
    def addOperators(self, num: str, target: int) -> List[str]:
        num_as_list = list(num)

        def get_i_to_j_num(i, j):
            num_as_string = ''.join(num_as_list[i:j+1])
            return int(num_as_string), num_as_string, int(num_as_string)

        def get_i_to_j_num_as_set(i, j):
            return set() if num[i] == '0' and i < j else {get_i_to_j_num(i, j)}

        def get_multiplication_table(num):
            dp, n  = [], len(num)
            dp = [None for _ in range(n)]
            for i in range(n-1, -1, -1):
                dp[i] = [None for _ in range(n)]
                for j in range(i, n):
                    dp[i][j] = get_i_to_j_num_as_set(i, j)
                    for k in range(i, j):
                        for left in dp[i][k]:
                            for right in dp[k+1][j]:
                                dp[i][j].add((left[0] * right[0], f"{left[1]}*{right[1]}", left[0] * right[0]))
            return dp

        def get_total_table(num, multiplication_table):
            dp, n  = multiplication_table, len(num)
            for i in range(n-1, -1, -1):
                for j in range(i, n):
                    for k in range(i, j):
                        for left in dp[i][k]:
                            for right in dp[k+1][j]:
                                dp[i][j].add((left[0] + right[0], f"{left[1]}+{right[1]}", left[2]))
                                dp[i][j].add((left[0] + right[0] - 2 * right[2], f"{left[1]}-{right[1]}", left[2]))
            return dp


        multiplication_table = get_multiplication_table(num)
        total_table = get_total_table(num, multiplication_table)
        return tuple(number[1] for number in total_table[0][-1] if number[0] == target)

113300