Translate

Wednesday, 4 February 2015

COEF(Coeficientes) spoj problem solution

HII guys this is one of the easy problem
the only thing that is u should know what
is multinomial theorem and how how to calculate
multinomial coefficient....
FORMULA::
 (n_1,n_2,...,n_k)!=((n_1+n_2+...+n_k)!)/(n_1!n_2!...n_k!)

here is my ac c++ solution is::



 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
#include<bits/stdc++.h>
using namespace std;
#define LL long long int
int main()
{
 LL fact[]={1,1,2,6,24,120,720,5040,40320,362880,3628800,39916800,479001600};
 int n,k,x,i;
 while(scanf("%d",&n)!=EOF)
 {
  scanf("%d",&k);
  LL ans=fact[n];
  for(i=1;i<=k;i++)
  {
   scanf("%d",&x);
   ans/=fact[x];
  }
  printf("%lld\n",ans);
 }
}

No comments:

Working With Java Collections