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++.










share|improve this question









New contributor




jdkLLm is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











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














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++.










share|improve this question









New contributor




jdkLLm is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











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












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++.










share|improve this question









New contributor




jdkLLm is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











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






share|improve this question









New contributor




jdkLLm is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




jdkLLm is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited Nov 10 at 12:51









πάντα ῥεῖ

71.1k970132




71.1k970132






New contributor




jdkLLm is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Nov 10 at 12:39









jdkLLm

1




1




New contributor




jdkLLm is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





jdkLLm is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






jdkLLm is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




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












  • 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

















active

oldest

votes






















active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

Top Tejano songwriter Luis Silva dead of heart attack at 64

ReactJS Fetched API data displays live - need Data displayed static

Evgeni Malkin