UVA- 369 Combination








 Tutorial (Bangla) : ডায়নামিক প্রোগ্রামিং এবং রিকার্শন দিয়ে NCR কম্বিনেশন


#include <stdio.h>
 long long int dp[120][120];
 long long int ncr(int n,int r)
{
    if(r==1)
    {
        return n;
    }
    if(n==r)
    {
        return 1;
    }
    if(r==0)
    {
        return 1;
    }
    if(dp[n][r]!=-1)
    {
        return dp[n][r];
    }
    else
    {
        dp[n][r]=ncr(n-1,r)+ncr(n-1,r-1);
        return dp[n][r];
    }

}
int main()
{
    long long int n,r,a;
    int i,j;
    while(scanf("%lld %lld",&n,&r)==2)
    {
        if(n==0 && r==0)
        {
            break;
        }
        else
        {
            for(i=0;i<120;i++)
            {
                for(j=0;j<120;j++)
                {
                    dp[i][j]=-1;

                }
            }
             printf("%lld things taken %lld at a time is %lld exactly.\n",n,r,ncr(n,r));


        }
    }
    return 0;
}

Download Coding Interview Book and Get More Tutorials for Coding and Interview Solution: Click Here

Download System Design Interview Book and Get More Tutorials and Interview Solution: Click Here

Do you need more Guidance or Help? Then Book 1:1 Quick Call with Me: Click Here

Share on Google Plus

About Ashadullah Shawon

I am Ashadullah Shawon. I am a Software Engineer. I studied Computer Science and Engineering (CSE) at RUET. I Like To Share Knowledge. Learn More: Click Here
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment