spoj ↣ classical ❱ pigbank ❱ Piggy-Bank

Piggy Bank is a simple variant of exact knapsack problem in which you can select more than 1 quantities of an item.


                          ❱❱     kp[x - 1][y],
kp[x][y] ❱❱ minimum of ❱❱ ❱❱❱    kp[x - 1][y - w[x]],
                          ❱❱     kp[x][y - w[x]],

and C++ is a stupid language but unfortunately it is fast and has stl.

How am I supposed to be aware that I have to allocate memory in the heap every time when I’m dealing with array sizes >= 100000. A language can expect a user to be familiar with a lot design practices but it shouldn’t expect him to be aware of what’s happening in the black box all the time!. today I got a SIGSEGV for trying to allocate memory on stack instead of heap. For 2 Hours I thought there is something wrong with my algorithm and later working with Valgrind confirmed that there are no leaks and then found this stupid stack, heap thing.

https://gist.github.com/7961bbc787f536302c55

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s