Subset sums with repetition using stacks [closed]
up vote
-5
down vote
favorite
I need a way to solve a subset sum problem. I have n elements and i need to get all the sums that adds up to a given number k. The problem is that i need to use a stack to this and it allows repetition.
An example:
array = 3,4,8,5
k = 10
output:
<3,3,4>
<5,5>
Preferably in C++.
c++ stack structure subset repetition
New contributor
closed as too broad by πάντα ῥεῖ, WhozCraig, Madhur Bhaiya, Shree, ekad Nov 10 at 13:19
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
up vote
-5
down vote
favorite
I need a way to solve a subset sum problem. I have n elements and i need to get all the sums that adds up to a given number k. The problem is that i need to use a stack to this and it allows repetition.
An example:
array = 3,4,8,5
k = 10
output:
<3,3,4>
<5,5>
Preferably in C++.
c++ stack structure subset repetition
New contributor
closed as too broad by πάντα ῥεῖ, WhozCraig, Madhur Bhaiya, Shree, ekad Nov 10 at 13:19
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
1
What have you tried by far?
– Ayxan
Nov 10 at 12:55
I've created a function that sums the actual element of the array. If the actual sum is less than the objective, it adds the same element again and push the element to my stack. If it's more than the objective, subtract the actual element from the sum and pop my stack and my count that indicates the actual elements is increased. If the sums is equal to the objective, i print and clear all elements from my stack.
– jdkLLm
Nov 10 at 13:08
if you should always add your code (what you have tried by far) to your questions, otherwise they are almost always close, as is this one
– Ayxan
Nov 10 at 13:22
add a comment |
up vote
-5
down vote
favorite
up vote
-5
down vote
favorite
I need a way to solve a subset sum problem. I have n elements and i need to get all the sums that adds up to a given number k. The problem is that i need to use a stack to this and it allows repetition.
An example:
array = 3,4,8,5
k = 10
output:
<3,3,4>
<5,5>
Preferably in C++.
c++ stack structure subset repetition
New contributor
I need a way to solve a subset sum problem. I have n elements and i need to get all the sums that adds up to a given number k. The problem is that i need to use a stack to this and it allows repetition.
An example:
array = 3,4,8,5
k = 10
output:
<3,3,4>
<5,5>
Preferably in C++.
c++ stack structure subset repetition
c++ stack structure subset repetition
New contributor
New contributor
edited Nov 10 at 12:51
πάντα ῥεῖ
71.1k970132
71.1k970132
New contributor
asked Nov 10 at 12:39
jdkLLm
1
1
New contributor
New contributor
closed as too broad by πάντα ῥεῖ, WhozCraig, Madhur Bhaiya, Shree, ekad Nov 10 at 13:19
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
closed as too broad by πάντα ῥεῖ, WhozCraig, Madhur Bhaiya, Shree, ekad Nov 10 at 13:19
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
1
What have you tried by far?
– Ayxan
Nov 10 at 12:55
I've created a function that sums the actual element of the array. If the actual sum is less than the objective, it adds the same element again and push the element to my stack. If it's more than the objective, subtract the actual element from the sum and pop my stack and my count that indicates the actual elements is increased. If the sums is equal to the objective, i print and clear all elements from my stack.
– jdkLLm
Nov 10 at 13:08
if you should always add your code (what you have tried by far) to your questions, otherwise they are almost always close, as is this one
– Ayxan
Nov 10 at 13:22
add a comment |
1
What have you tried by far?
– Ayxan
Nov 10 at 12:55
I've created a function that sums the actual element of the array. If the actual sum is less than the objective, it adds the same element again and push the element to my stack. If it's more than the objective, subtract the actual element from the sum and pop my stack and my count that indicates the actual elements is increased. If the sums is equal to the objective, i print and clear all elements from my stack.
– jdkLLm
Nov 10 at 13:08
if you should always add your code (what you have tried by far) to your questions, otherwise they are almost always close, as is this one
– Ayxan
Nov 10 at 13:22
1
1
What have you tried by far?
– Ayxan
Nov 10 at 12:55
What have you tried by far?
– Ayxan
Nov 10 at 12:55
I've created a function that sums the actual element of the array. If the actual sum is less than the objective, it adds the same element again and push the element to my stack. If it's more than the objective, subtract the actual element from the sum and pop my stack and my count that indicates the actual elements is increased. If the sums is equal to the objective, i print and clear all elements from my stack.
– jdkLLm
Nov 10 at 13:08
I've created a function that sums the actual element of the array. If the actual sum is less than the objective, it adds the same element again and push the element to my stack. If it's more than the objective, subtract the actual element from the sum and pop my stack and my count that indicates the actual elements is increased. If the sums is equal to the objective, i print and clear all elements from my stack.
– jdkLLm
Nov 10 at 13:08
if you should always add your code (what you have tried by far) to your questions, otherwise they are almost always close, as is this one
– Ayxan
Nov 10 at 13:22
if you should always add your code (what you have tried by far) to your questions, otherwise they are almost always close, as is this one
– Ayxan
Nov 10 at 13:22
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
1
What have you tried by far?
– Ayxan
Nov 10 at 12:55
I've created a function that sums the actual element of the array. If the actual sum is less than the objective, it adds the same element again and push the element to my stack. If it's more than the objective, subtract the actual element from the sum and pop my stack and my count that indicates the actual elements is increased. If the sums is equal to the objective, i print and clear all elements from my stack.
– jdkLLm
Nov 10 at 13:08
if you should always add your code (what you have tried by far) to your questions, otherwise they are almost always close, as is this one
– Ayxan
Nov 10 at 13:22