Click here to Skip to main content
14,661,643 members
Home » Discussions » C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Visual Studio and Windows SDKs - need some experienced comments about SDK usage and RTLs Pin
Mircea Neacsu12-Jun-20 2:24
MemberMircea Neacsu12-Jun-20 2:24 
GeneralRe: Visual Studio and Windows SDKs - need some experienced comments about SDK usage and RTLs Pin
charlieg12-Jun-20 8:27
Membercharlieg12-Jun-20 8:27 
GeneralRe: Visual Studio and Windows SDKs - need some experienced comments about SDK usage and RTLs Pin
Mircea Neacsu12-Jun-20 8:59
MemberMircea Neacsu12-Jun-20 8:59 
QuestionRecursion to normal way Pin
iNoor728-Jun-20 9:28
MemberiNoor728-Jun-20 9:28 
AnswerRe: Recursion to normal way Pin
jeron18-Jun-20 9:47
Memberjeron18-Jun-20 9:47 
GeneralRe: Recursion to normal way Pin
iNoor728-Jun-20 11:00
MemberiNoor728-Jun-20 11:00 
GeneralRe: Recursion to normal way Pin
David Crow9-Jun-20 3:15
MemberDavid Crow9-Jun-20 3:15 
GeneralRe: Recursion to normal way Pin
harold aptroot8-Jun-20 10:30
Memberharold aptroot8-Jun-20 10:30 
iNoor72 wrote:
but I want someone to re-write the code in a normal form (For loops, while loops, etc...)

Good plan.

There are some different ways to do that:
  • The "naive" way: iterate over all sets. That's easy, because sets can represented as integers, where bit i being set means "item i is in the set" and bit i not being set meaning "item i is not in the set". Iterating over ranges of integers, well, that's just a normal loop. Slow but simple. Simple in terms of code at least. There is a certain leap of logic to it (set=integer) that is not obvious for beginners.
  • The "mechanical" way: traverse the same recursion-tree, but with iteration and an explicit stack. That's a straightforward refactoring, just tricky (for a human) to get right. Hypothetically this refactoring could be done by a computer, so I call it mechanical - it doesn't require any insight in the Knapsack problem.
  • The "clever" way: fill an array iteratively, so that every result for a unique combination of (n, W) is only computed once, starting with the bottom of the recursion-tree and working up. The original algorithm will often reach the same state through different paths and then recalculate the same thing, that wasted work is avoided this way. This is also known as "Dynamic Programming", which is a far too fancy term for what it is..
Any way you go with, you should be able to make some sort of progress. If you can't finish it then you would have a real question to ask - or to look up. Knapsack has been done to death, there are already too many introductory articles about it, there have to be some that will help you.
GeneralRe: Recursion to normal way Pin
iNoor728-Jun-20 11:01
MemberiNoor728-Jun-20 11:01 
GeneralRe: Recursion to normal way Pin
harold aptroot8-Jun-20 11:11
Memberharold aptroot8-Jun-20 11:11 
GeneralRe: Recursion to normal way Pin
iNoor728-Jun-20 11:39
MemberiNoor728-Jun-20 11:39 
GeneralRe: Recursion to normal way Pin
Dave Kreskowiak8-Jun-20 16:44
mveDave Kreskowiak8-Jun-20 16:44 
AnswerRe: Recursion to normal way Pin
Member 79891228-Jun-20 10:38
MemberMember 79891228-Jun-20 10:38 
GeneralRe: Recursion to normal way Pin
iNoor728-Jun-20 11:03
MemberiNoor728-Jun-20 11:03 
GeneralRe: Recursion to normal way Pin
Richard MacCutchan8-Jun-20 21:33
mveRichard MacCutchan8-Jun-20 21:33 
GeneralExercise Pin
Member 79891228-Jun-20 22:31
MemberMember 79891228-Jun-20 22:31 
GeneralRe: Exercise Pin
Richard MacCutchan8-Jun-20 22:34
mveRichard MacCutchan8-Jun-20 22:34 
JokeRe: Exercise Pin
Peter_in_27808-Jun-20 22:43
professionalPeter_in_27808-Jun-20 22:43 
GeneralRe: Exercise Pin
Member 79891229-Jun-20 2:50
MemberMember 79891229-Jun-20 2:50 
GeneralRe: Exercise Pin
Richard MacCutchan9-Jun-20 3:39
mveRichard MacCutchan9-Jun-20 3:39 
GeneralRe: Exercise Pin
Member 79891229-Jun-20 3:59
MemberMember 79891229-Jun-20 3:59 
GeneralRe: Exercise Pin
Richard MacCutchan9-Jun-20 4:11
mveRichard MacCutchan9-Jun-20 4:11 
GeneralRe: Exercise Pin
Richard MacCutchan9-Jun-20 4:29
mveRichard MacCutchan9-Jun-20 4:29 
GeneralRe: Exercise Pin
Richard MacCutchan9-Jun-20 20:56
mveRichard MacCutchan9-Jun-20 20:56 
GeneralRe: Exercise Pin
Member 79891229-Jun-20 22:08
MemberMember 79891229-Jun-20 22:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.