Dev Skill 61 Divide In Grid





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


#include <bits/stdc++.h>
using namespace std;
long long int dp[32][32];
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 i,j,k,l,m,q,t,f,v,w,p;
    cin>>t;
    for(k=1;k<=t;k++)
    {
        cin>>v>>w;
        q=v+w;
        m=max(v,w);
        for(i=0;i<32;i++)
        {
            for(j=0;j<32;j++)
            {
                dp[i][j]=-1;

            }
        }
        cout<<ncr(q,m)<<endl;
    }

    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