Silkroad Online Forums

A community forum for the free online game Silkroad Online. Discuss Silkroad Online, read up on guides, and build your character and skills.

Faq Search Members Chat  Register Profile Login

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Programming question
PostPosted: Sat Dec 15, 2012 5:24 pm 
Frequent Member
User avatar
Offline

Joined: Sep 2012
Posts: 1284
Location: SuddenDeath
Hey guys. I was wondering if anyone here knows something about programming (I assume at least someone does). I was trying to figure Knapsack problem out, and I did. I figured out the 0/1 Knapsack problem, as I watched an explanation on YouTube. I did write a code myself after hearing an explanation (there was no pseudo code). Here it is (it's in Pascal, don't flame me):
Spoiler!


Now, my question is: Does anybody here has a link to the explanation of Knapsack problem with infinite number of items or has a code for it? It doesn't matter what programming language it is, although I prefer pseudo code.

_________________
Image
[SuddenDeath*PlsMeRectal]
TickleMeAnal

Image


Spoiler!


Top
 Profile  
 
 Post subject: Re: Programming question
PostPosted: Mon Dec 24, 2012 1:17 am 
Addicted Member
User avatar
Offline

Joined: Apr 2008
Posts: 2612
Location: Texas
Quote:
Let

M = Amount need to fill
w[] = Array of weights
dp[] = Array of optimal fill(dp[i] contains minimum number of items needed to fill weight i).
Code:
initialize the dp array with INFINITY, dp[0] = 0;
for(i = 0;i<size of w;i++) {
    for(j = 1;j<=M;j++) {
       if(j-w[i] >= 0) {
          dp[j] = min(dp[j], dp[j-w[i]]+1);
       }
    }
}

final solution is the value of dp[M];


http://people.csail.mit.edu/bdean/6.046/dp/dp_2.swf

The above may help. I grabbed it off stackoverflow.

_________________
Image


Top
 Profile  
 
 Post subject: Re: Programming question
PostPosted: Mon Dec 24, 2012 12:07 pm 
Frequent Member
User avatar
Offline

Joined: Sep 2012
Posts: 1284
Location: SuddenDeath
EvGa wrote:
Quote:
Let

M = Amount need to fill
w[] = Array of weights
dp[] = Array of optimal fill(dp[i] contains minimum number of items needed to fill weight i).
Code:
initialize the dp array with INFINITY, dp[0] = 0;
for(i = 0;i<size of w;i++) {
    for(j = 1;j<=M;j++) {
       if(j-w[i] >= 0) {
          dp[j] = min(dp[j], dp[j-w[i]]+1);
       }
    }
}

final solution is the value of dp[M];


http://people.csail.mit.edu/bdean/6.046/dp/dp_2.swf

The above may help. I grabbed it off stackoverflow.


I thought of something similar. I will check it. Thanks.

_________________
Image
[SuddenDeath*PlsMeRectal]
TickleMeAnal

Image


Spoiler!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group