416. 分割等和子集
https://leetcode-cn.com/problems/partition-equal-subset-sum/
一:dp
用dp[i][j] = True
表示能用前i个数凑出j,False就是不能。将该题转换为01背包问题,即数组中的数能否凑出sum/2,能则说明存在一种分割方法将数组等分。
i=0表示没有数,因此i=1表示数组0号元素,即dp[i][j]
表示能否用数组[0...i-1]
凑出
base case
最后更新于
https://leetcode-cn.com/problems/partition-equal-subset-sum/
用dp[i][j] = True
表示能用前i个数凑出j,False就是不能。将该题转换为01背包问题,即数组中的数能否凑出sum/2,能则说明存在一种分割方法将数组等分。
i=0表示没有数,因此i=1表示数组0号元素,即dp[i][j]
表示能否用数组[0...i-1]
凑出
base case
最后更新于