Computer Science Canada Dynamic Programming |
Author: | zero-impact [ Mon Feb 23, 2009 10:57 pm ] | ||||
Post subject: | Dynamic Programming | ||||
I have been working on this question for a while now and can't seem to figure out what is happening. My situation is that out of the 3 test cases only the first two will produce a correct answer. The strange part is, is that I have been using a friends Turing solution to learn and make a c++ solution of my own (Thank you saltpro15). My c++ solution seems to be identical (even more so after a change to be exactly the same) to the Turing version yet it still only gets 2/3 and the Turing version 3/3. Here is the code.
input file |
Author: | Analysis Mode [ Mon Feb 23, 2009 11:38 pm ] |
Post subject: | Re: Dynamic Programming |
int dp [height]; is your DP array declaration, yet at the bottom, you output dp[height]. I think it shold be dp[height+1] (for both output and declaration) That might be your problem. Dun worry, I've had the same problesm when translating code from pascal to c++ myself. your algorithm looks fine. |
Author: | zero-impact [ Tue Feb 24, 2009 7:03 am ] |
Post subject: | RE:Dynamic Programming |
Hmmm I don't think that is it. Because it works for the first two cases and not the third :s |
Author: | saltpro15 [ Tue Feb 24, 2009 3:12 pm ] |
Post subject: | RE:Dynamic Programming |
umm... I was consulting with A.J. as to how to do this problem, and I think I saved his solution over mine, because that is not my code, although it does look a lot like it, I take no credit for that |
Author: | saltpro15 [ Tue Feb 24, 2009 3:43 pm ] | ||
Post subject: | Re: Dynamic Programming | ||
This is my version, oops, sorry AJ
|
Author: | A.J [ Tue Feb 24, 2009 4:28 pm ] |
Post subject: | Re: Dynamic Programming |
it looks nice looks like it should work |
Author: | saltpro15 [ Tue Feb 24, 2009 5:40 pm ] |
Post subject: | RE:Dynamic Programming |
should, yet doesn't... i'm baffled zeroimpact, that should work, maybe c++ is having a crazy day again |
Author: | saltpro15 [ Tue Feb 24, 2009 5:45 pm ] |
Post subject: | RE:Dynamic Programming |
btw, -6 karma ????!!!?! paul, how do I just know that at least 5 of these are from you |
Author: | A.J [ Tue Feb 24, 2009 5:53 pm ] | ||||
Post subject: | Re: Dynamic Programming | ||||
I found your mistake
should be :
the first loop must go from 0 -> nBlocks - 1 (since blocks[nBlocks] doesn't hold anything) |
Author: | saltpro15 [ Tue Feb 24, 2009 6:00 pm ] |
Post subject: | RE:Dynamic Programming |
umm A.J, i don't see a difference between those blocks... |
Author: | zero-impact [ Tue Feb 24, 2009 6:01 pm ] |
Post subject: | RE:Dynamic Programming |
Did you test that A.J? Because even with that change it still only gets the first two cases for me. |
Author: | saltpro15 [ Tue Feb 24, 2009 6:03 pm ] |
Post subject: | RE:Dynamic Programming |
can't edit replied to post... irritating well no matter, I found it, and it outputs the same thing |