{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

2c03-review - 00066 - /initializing the table for(int...

Info icon This preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
9 int Factorial(int n){ int f=1; for(int i=1;i<=n;i++) f*=i; return f; } //DnC implements solution to 10(a). it uses divide and conquer method int DnC(int n,int m){ if(m==0 || n==m) return 1; else return DnC(n-1,m)+DnC(n-1,m-1); } //DP implements solution to 10(c). it uses dynamic programing technique method int DP(int n,int m){ //allocating the table int **L; L=new int*[n+1]; for(int i=0;i!=n+1;i++) L[i]=new int[m+1];
Image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: //initializing the table for(int i=0;i!=n+1;i++) L[i][0]=1; for(int i=0;i!=m+1;i++) L[i][i]=1; //filling the table for(int i=1;i!=n+1;i++) for(int j=1;j!=m+1&&j<i;j++) L[i][j]=L[i-1][j]+L[i-1][j-1]; //result is in L[n][m] int r=L[n][m]; for(int i=0;i!=n+1;i++) delete L[i]; delete L; return r; } void main(){ cout<<"DnC(14,10):\t"<<DnC(14,10)<<endl; cout<<"DP(14,10):\t"<<DP(14,10)<<endl;...
View Full Document

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern