<p>You are installing a billboard and want it to have the largest height. The billboard will have two steel supports, one on each side. Each steel support must be an equal height.</p>

<p>You are given a collection of <code>rods</code> that can be welded together. For example, if you have rods of lengths <code>1</code>, <code>2</code>, and <code>3</code>, you can weld them together to make a support of length <code>6</code>.</p>

<p>Return <em>the largest possible height of your billboard installation</em>. If you cannot support the billboard, return <code>0</code>.</p>

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

<pre>
<strong>Input:</strong> rods = [1,2,3,6]
<strong>Output:</strong> 6
<strong>Explanation:</strong> We have two disjoint subsets {1,2,3} and {6}, which have the same sum = 6.
</pre>

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

<pre>
<strong>Input:</strong> rods = [1,2,3,4,5,6]
<strong>Output:</strong> 10
<strong>Explanation:</strong> We have two disjoint subsets {2,3,5} and {4,6}, which have the same sum = 10.
</pre>

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

<pre>
<strong>Input:</strong> rods = [1,2]
<strong>Output:</strong> 0
<strong>Explanation:</strong> The billboard cannot be supported, so we return 0.
</pre>

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

<ul>
	<li><code>1 &lt;= rods.length &lt;= 20</code></li>
	<li><code>1 &lt;= rods[i] &lt;= 1000</code></li>
	<li><code>sum(rods[i]) &lt;= 5000</code></li>
</ul>

class Solution:
    def tallestBillboard(self, rods: List[int]) -> int:
        n = len(rods)
        s = sum(rods)

        # Hence Better approach 
        # convert 3 parameters to 2 ... by using diff of s1 and s2 as param
        # s1 == s2 we return s1 ... hence if diff == 0 we return True(i.e ., 0) else -1e9
        dp = {}
        for i in range(n): dp[i] = {}

        def solve(ind , diff):
            if ind == n:
                if diff == 0: return 0
                return -1e9

            if diff in dp[ind]: return dp[ind][diff]

            not_take = solve( ind+1 , diff )

            # take in rod1
            """ Here we need to add  rods[ind] 
            Here to know length we are tracking one rod element alone ..!
            """ 
            take_1 = rods[ind] + solve( ind+1 , diff+rods[ind] )
            
            # take in rod2 ...hence reduce it from diff
            take_2 = solve( ind+1 , diff-rods[ind])

            dp[ind][diff] = max( not_take , max( take_1 , take_2 ))
            return dp[ind][diff]
            
        return solve( 0 , 0 )
        
        # Memoization ..!
        # Here it would be 20 x 5000 x 5000  ==> memory limit exceeded
        """
        dp = [[[-1 for i in range(s+1)] for j in range(s+1)] for k in range(n+1)]
        """
        # Recursion ..!!
        """
        def solve( ind , r1 , r2 ):
            if ind == n-1:
                if r1 + rods[ind] == r2: return r2
                elif r1 == r2 + rods[ind]: return r1
                return 0
            
            not_take = solve( ind+1 , r1 , r2 )

            take_1 = solve( ind+1 , r1+rods[ind] , r2 )
            take_2 = solve( ind+1 , r1 , r2+rods[ind] )

            return max( not_take , max( take_1 , take_2 ))
        
        return solve( 0 , 0 , 0 )
        """
94900