<h3><a title="题目描述" href="https://leetcode-cn.com/problems/partition-equal-subset-sum/">题目描述</a></h3>
![file](https://i.loli.net/2020/10/11/iws9JXozDmAvkcV.png)
<h4>方法一</h4>
<pre class="EnlighterJSRAW" data-enlighter-language="python">class Solution:
def canPartition(self, nums: List[int]) -> bool:
n = len(nums)
if n < 2:
return False
total = sum(nums)
maxNum = max(nums)
if total % 2 !=0:
return False
target = total // 2
if maxNum > target:
return False
dp = [[0] * (target + 1) for _ in range(n)]
for i in range(n):
dp[i][0] = True
dp[0][nums[0]] = True
for i in range(1, n):
num = nums[i]
for j in range(1, target + 1):
if j >= num:
dp[i][j] = dp[i - 1][j] | dp[i - 1][j - num]
else:
dp[i][j] = dp[i - 1][j]
return True if(dp[n - 1][target]==1) else False
</pre>
<p> </p>
## 思路
- 回溯超时
- DP没想到
-->![file](https://i.loli.net/2020/10/11/w19xBoGagCtePWh.png)
太难啦
Leetcode416 分割等和子集[DP]