![]() |
|
#1
|
|||
|
|||
Calculating Stirling Number Of The Second KindHi there,
I have to make a program that calculates stirling number of the second kind (http://en.wikipedia.org/wiki/Stirling_numbers_of_the_second_kind), using dynamic programming. I wrote something like this, and it works for smaller numbers but it fails when n=5, k=4 (stirling number is 10, and my program returns 6) CPP / C++ / C Code:
|
|||
|
#2
|
|||
|
|||
Re: Calculating Stirling Number Of The Second KindQuote:
Since your index values go up to and including n and k, the array dimension must be a[n+1][k+1]. See Footnote. Anyhow, with proper limits on the array and with slight modifications to your main() function, after commenting out print statements in your stirling() function I get Code:
Regards, Dave Footnote: Even if your compiler accepts variable length arrays, it's not part of the current C++ standard. Allocation using new would be generally recommended if portability is a consideration. Last edited by davekw7x : 19-Mar-2010 at 11:48.
|
|
#3
|
|||
|
|||
Re: Calculating Stirling Number Of The Second KindThank you so much! It now works quite well.
In this case it's ok that I'm using variable lenght arrays, since it's only an examplatory implementation of an algorythm I had to made for a homework, but I'll keep it in mind for the future. Thanks again, your reply had solved all my problems. - Nathalie |
|
#4
|
|||
|
|||
Re: Calculating Stirling Number Of The Second KindQuote:
Regards, Dave |
Recent GIDBlog
R for statistics by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Help in Calculating week number | ahbi82 | C Programming Language | 10 | 08-Dec-2009 05:49 |
| Converting a number amount to text | Godzilla | C++ Forum | 5 | 31-Mar-2006 11:38 |
| calculating number of bytes | Haru | C++ Forum | 3 | 11-Dec-2005 01:15 |
| Anyone can write a program code for this??? | chriskan76 | C Programming Language | 1 | 19-Oct-2004 20:25 |
| Apache2 config issues | monev | Apache Web Server Forum | 2 | 28-Jun-2004 06:19 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The