题解:dp[j]表示目标和为j时的最大组合种数
class Solution {
public:int dp[1005];int findTargetSumWays(vector<int>& nums, int target) {int val;int sum=0;for(int i=0;i<nums.size();i++){sum+=nums[i];}int w=sum+target;if(w%2==1){return 0;}else{val=w/2;if(val<0) return 0;dp[0]=1;for(int i=0;i<nums.size();i++){for(int j=val;j>=nums[i];j--){dp[j]+=dp[j-nums[i]];}}return dp[val];}}
};
class Solution {
public:// int dp[3005];int lastStoneWeightII(vector<int>& stones) {int sum=0;vector<int>dp(3005,0);for(int i=0;i<stones.size();i++){sum+=stones[i];} int x=sum;sum=sum/2;// memset(dp,0,sizeof(dp));for(int i=1;i<=stones.size();i++){for(int j=sum;j>=stones[i-1];j--){dp[j]=max(dp[j-stones[i-1]]+stones[i-1],dp[j]);}}return abs(x-2*dp[sum]);// return 0;}
};
class Solution {
public:int dp[205][20005];bool canPartition(vector<int>& nums) {int res=0;for(int i=0;i<nums.size();i++){res+=nums[i];}if(res%2==1){return false;}else{int n=nums.size();int val=res/2;// vector<vector<int>> dp(n+1,vector<int>(val+5));for(int j=0;j<=val;j++){if(j>=nums[0]){dp[0][j]=nums[0];}}for(int i=1;i<n;i++){for(int j=0;j<=val;j++){if(j<nums[i]) dp[i][j]=dp[i-1][j];else{dp[i][j]=max(dp[i-1][j],dp[i-1][j-nums[i]]+nums[i]);}}}int w=dp[n-1][val];if(w==val){return true;}else {return false;}}}
};
class Solution {
public:int dp[105][105];int findMaxForm(vector<string>& strs, int m, int n) {int N=strs.size();vector<int>Mnum(N+5,0);vector<int>Nnum(N+5,0);for(int i=0;i<strs.size();i++){string s1=strs[i];for(int j=0;j<s1.size();j++){if(s1[j]=='0'){Mnum[i]++;}else{Nnum[i]++;}} }memset(dp,0,sizeof(dp));for(int i=0;i<N;i++){for(int j=m;j>=Mnum[i];j--){for(int k=n;k>=Nnum[i];k--){dp[j][k]=max(dp[j-Mnum[i]][k-Nnum[i]]+1,dp[j][k]);}}}return dp[m][n];}
};