<p>You are given an integer array <code>nums</code> and an integer <code>target</code>.</p>

<p>You want to build an <strong>expression</strong> out of nums by adding one of the symbols <code>&#39;+&#39;</code> and <code>&#39;-&#39;</code> before each integer in nums and then concatenate all the integers.</p>

<ul>
	<li>For example, if <code>nums = [2, 1]</code>, you can add a <code>&#39;+&#39;</code> before <code>2</code> and a <code>&#39;-&#39;</code> before <code>1</code> and concatenate them to build the expression <code>&quot;+2-1&quot;</code>.</li>
</ul>

<p>Return the number of different <strong>expressions</strong> that you can build, which evaluates to <code>target</code>.</p>

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

<pre>
<strong>Input:</strong> nums = [1,1,1,1,1], target = 3
<strong>Output:</strong> 5
<strong>Explanation:</strong> There are 5 ways to assign symbols to make the sum of nums be target 3.
-1 + 1 + 1 + 1 + 1 = 3
+1 - 1 + 1 + 1 + 1 = 3
+1 + 1 - 1 + 1 + 1 = 3
+1 + 1 + 1 - 1 + 1 = 3
+1 + 1 + 1 + 1 - 1 = 3
</pre>

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

<pre>
<strong>Input:</strong> nums = [1], target = 1
<strong>Output:</strong> 1
</pre>

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

<ul>
	<li><code>1 &lt;= nums.length &lt;= 20</code></li>
	<li><code>0 &lt;= nums[i] &lt;= 1000</code></li>
	<li><code>0 &lt;= sum(nums[i]) &lt;= 1000</code></li>
	<li><code>-1000 &lt;= target &lt;= 1000</code></li>
</ul>

class Solution {
public:
    int findTargetSumWays(vector<int>& nums, int target) {
        int sum = 0;
        for (auto num : nums)
            sum += abs(num);
        target = abs(target);
        if (target > sum) return 0;
        vector<vector<int>> dp(nums.size()+1, vector<int>(2*sum+1, 0));
        dp[0][sum] = 1;

        for(int i=1;i<=nums.size();i++) {
            for(int j=0;j<2*sum+1;j++) {
                if (j-nums[i-1] >= 0)
                    dp[i][j] += dp[i-1][j-nums[i-1]];
                if (j+nums[i-1] < 2*sum+1)
                    dp[i][j] += dp[i-1][j+nums[i-1]];
            }
        }

        return dp[nums.size()][sum+target];
    }
};


// dp[i][j] represents the number of qualifired conbinations when considering taking pre ith elements withe the sum of j

// dp[i+1][j] = dp[i][j-nums[i]] + dp[i][j+nums[i]]


// 0 0 0 1 0 0 0
// 0 0 1 0 1 0 0
// 0 1 0 2 0 1 0
// 1 0 3 0 3 0 1
// 0 4 0 6 0 4 0
// 5 0 100 100 5
25063