CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Threaded View

  1. #1
    Join Date
    Feb 2007
    Posts
    31

    Binomial Coefficients

    Code:
    int dynamicBinomial(int N, int k)
     {
     	vector< vector<int> >table(N,vector<int>(k));
    	
    	for (int j = 0; j < N; j++) 
    		table[j][0] = 1;
     	
     	for (int i = 0; i < N; i++)
     	   {
    		for (int j = 0; j < k; j++)
    		 {
    			table[i][j] = table[i-1][j-1] + table[i-1][j];
    		 }
     	   }
     	 return table[N-1][k-1];
     }
    This function is supposed to return the binomial coefficients for N and k using dynamic programming, but it does not return the correct result. Does anybody know what is wrong with the code?
    Last edited by Ehump20; March 1st, 2007 at 09:47 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured