GOODB - Good Predictions - SPOJ Solution C++

  Problem Link : GOODB 


👉 Hint : Number theory with combinations

 


✅ C++ Solution :

 
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll m=pow(10,9)+7;

ll power(ll x,ll n)
{
    if(n==0)
        return 1;
    ll y=power(x,n/2);
    y=(y*y)%m;
    if(n%2!=0)
        y=(y*x)%m;
    return y;    
    
}

ll comb(ll n,ll r)
{
	ll l=min(n-r-1,r-1);
	ll num=1,den=1;
	for(ll i=0;i<=l;i++)
		num=(num*(n-i))%m;
	for(ll i=0;i<=l;i++)
	    den=(den*(i+1))%m;
	den=power(den,m-2);    
	return (num*den)%m;
}

int main()
{
	ll n,w,t,r;
	cin>>n>>w>>t>>r;
	ll x=(comb(n,w)*comb(n-w,t))%m;
	cout<<x;
} 



 

Thank you for your patience reading. If you enjoyed this post, I’d be very grateful if you’d help it spread by emailing it to a friend, or sharing it on Whatsapp or Facebook. 

😇Happy Learning!!