class Solution {
public:int lastStoneWeightII(vector<int>& stones) {int sum = 0;for(int a : stones){sum += a;}int target = sum / 2;vector<int> dp(target + 1, 0);for(int i = 0; i < stones.size(); i++){for(int j = target; j >= stones[i]; j--){dp[j] = max(dp[j], dp[j - stones[i]] + stones[i]);}}return sum - dp[target] * 2;}
};
class Solution {
public:int findTargetSumWays(vector<int>& nums, int target) {int sum = 0;for(int a : nums){sum += a;}if(abs(target) > sum) return 0;if((sum + target) % 2) return 0;int tar = (sum + target) / 2;vector<int> dp(tar + 1, 0);dp[0] = 1;for(int i = 0; i < nums.size(); i++){for(int j = tar; j >= nums[i]; j--){dp[j] += dp[j - nums[i]];}}return dp[tar];}
};
class Solution {
public:int findMaxForm(vector<string>& strs, int m, int n) {vector<vector<int>> dp(m + 1, vector<int> (n + 1, 0));for(string str : strs){int numZero = 0;int numOne = 0;for(char s : str){if(s == '0') numZero++;else numOne++;}for(int i = m; i >= numZero; i--){for(int j = n; j >= numOne; j--){dp[i][j] = max( dp[i][j], dp[i-numZero][j-numOne] + 1 );}}}return dp[m][n];}
};