Find the errors and correct then in the given code with proper comments. class Solution { public: vector DistinctSum(vectornums){ vectorans; int sum = 0; int n = nums.size() for(int i=0;i
Find the errors and correct then in the given code with proper comments.
class Solution {
public:
vector<int>ans;
int sum = 0;
int n = nums.size()
for(int i=0;i<n;i+){
}
bool dp[n+1][sum+1];
for(int i=0;i<=n;i+){
dp[i][0] = true
}
for(int i=1;i<=n;i++){
for(int j = 1;j<sum;j++){
if(dp[i-1][j]=true){
dp[i][j+nums[i-1]] = true;
}
}
}
for(int j=0;j<=sum;j++){
if(dp[n][j]==false){
ans.push_back(j);
}
}
return a;
}
};
Ques: Given a set of integers, find all distinct sums that can be generated from the subsets of the given sets.
![](/static/compass_v2/shared-icons/check-mark.png)
Find the errors in the given code and correct them with proper comments.
Problem Statement:
Given a set of integers, find all distinct sums that can be generated from the subsets of the given sets.
Step by step
Solved in 3 steps with 2 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)