➤ Problem Link : 553A. Kyoya and Colored Balls
✅ C++ Solution :
#include<bits/stdc++.h> using namespace std; #define ll long long int ll m = 1000000007 ; ll fact[10000001]; ll power(ll a,ll b) { if(b==0) return 1; ll x=power(a,b/2); x=(x*x)%m; if(b%2==1) x=(x*a)%m; return x; } ll comb(ll n, ll r) { if(n==0) return 1; return (fact[n]*power(fact[r]*fact[n-r]%m,m-2))%m; } int main() { int k,c; cin>>k; ll ans=1; ll len=0; fact[0]=1; for(int i=1;i<=1000000;i++) fact[i]=(fact[i-1]*i)%m; for(int i=1;i<=k;i++) { cin>>c; ans=(ans*comb(len+c-1,c-1))%m; len+=c; } cout<<ans<<"\n"; }
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!!
➤ Problem Link : 553A. Kyoya and Colored Balls
✅ C++ Solution :
#include<bits/stdc++.h> using namespace std; #define ll long long int ll m = 1000000007 ; ll fact[10000001]; ll power(ll a,ll b) { if(b==0) return 1; ll x=power(a,b/2); x=(x*x)%m; if(b%2==1) x=(x*a)%m; return x; } ll comb(ll n, ll r) { if(n==0) return 1; return (fact[n]*power(fact[r]*fact[n-r]%m,m-2))%m; } int main() { int k,c; cin>>k; ll ans=1; ll len=0; fact[0]=1; for(int i=1;i<=1000000;i++) fact[i]=(fact[i-1]*i)%m; for(int i=1;i<=k;i++) { cin>>c; ans=(ans*comb(len+c-1,c-1))%m; len+=c; } cout<<ans<<"\n"; }
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!!