1.

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * Angewandte Mathematik, SS11
 * Problem: 10105 - Polynomial Coefficient
 * Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=13&page=show_problem&problem=1046
 *
 * @author Benedikt Zšnnchen
 * @author Erik Wenzel
 * @version 1.0, 10/05/2011
 *
 * Method : Precalculate Faculty Ponomialcoefficient = (n!)(k_1!k_2!...)
 * Status : Accepted    
 * Runtime: 0.448
 */
public class Main
{
    public static void main(String[] args) throws IOException
    {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        long[] fak = getFakArray(12);
       
       
        int n = 0;
        int k = 0;
        String line;
       
        while((line=reader.readLine()) != null)
        {
            String[] splitA = line.split(" ");
            n = Integer.parseInt(splitA[0]);
            k = Integer.parseInt(splitA[1]);
            long sum = 1;
            splitA = reader.readLine().split(" ");
           
            if(k<splitA.length)
            {
                System.out.println(0);
            }
            else
            {
                for(int i = 0; i < k; i++)
                {
                    sum *= fak[Integer.parseInt(splitA[i])];
                }
                System.out.println((fak[n]/sum));
            }           
        }
    }
   
    /**
     * calculate the all values from 0!>=n>=limt! and return them in an Array
     * @param limit
     * @return limit! Array
     */
    public static long[] getFakArray(int limit)
    {
        long[] fak = new long[limit+1];
        fak[0]=1;       
        for(int i = 1; i<=limit; i++)
        {
            fak[i] = i*fak[i-1];
        }
        return fak;
    }
}


2.

package sem2.am.polynomialcoefficients;

/**
 * Angewandte Mathematik, SS11
 * Problem: 10105 - Polynomial Coefficients
 * Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=13&page=show_problem&problem=1046
 *
 * @author Florian Stein
 * @author Franz Sommer
 * @version 1.0, 05/22/2011
 *
 * Method : Ad-Hoc
 * Status : Accepted
 * Runtime: 0.664
 */

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        // schleife faelle
        while (sc.hasNext()) {

            // einlesen der ersten zeile
            int n = sc.nextInt();
            int k = sc.nextInt();

            // array fuer k
            List<Integer> list = new ArrayList<Integer>();

            // werte aufnehmen
            for (int i = 0; i < k; i++) {
                list.add(sc.nextInt());
            }

            // alle factoritaeten multiplizieren
            double productfak = 1;
            for (int i = 0; i < k; i++) {
                productfak = productfak * fakt(list.get(i));
            }

            // fakultaet von n durch dem produkt teilen
            System.out.println(productfak);
            double C = fakt(n) / productfak;

            // ausgabe
            System.out.println((int) C);
        }
    }

    // fakultaet
    private static double fakt(double n) {
        if (n <= 1)
            return (double) 1;
        return (n * fakt(n - 1));
    }
}

3.

/**

* Angewandte Mathematik, SS11

* Problem:10105-PolynomialCoefficients

* Link: http://uva.onlinejudge.org/external/101/10105.html

* @author Brielbeck, Daniel

* @author Weber, Georg

* @version 1.0, 05/10/2011

* Method : Ad-Hoc

* Status : Accepted

* Runtime: 0.576

*/

import java.io.BufferedReader;

import java.io.InputStreamReader;



public class Main {

public static void main(String[] args) throws Exception {

int factorials[] =
{1,1,2,6,24,120,720,5040,40320,362880,3628800,39916800,479001600};

String[] tmp;

BufferedReader in = new BufferedReader(new
InputStreamReader(System.in));

String input;



while ((input = in.readLine()) != null) {

int n = Integer.parseInt(input.split(" ")[0]);

int k = Integer.parseInt(input.split(" ")[1]);

int c = factorials[n];

tmp = in.readLine().split(" ");

for (int i = 0; i < k; i++)

c /= factorials[Integer.parseInt(tmp[i])];

System.out.println(c);

}

}

}

4.

import java.io.*;
import java.util.StringTokenizer;

/**
* FWP, Angewandte Mathematik, SS11
* Problem: 10105 Polynomial Coefficients
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=13&page=show_problem&problem=1046
*
* @author Sebastian Stumpf
* @author Benjamin Vogt
* @version 1.0, 2011-05-29 09:39:09
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 0.376
*/
public class Main
{
/**
* returns the coefficient of a given x1^p1*x2^p2*x3^p3*...*xn^pn, using the multinpomial theorem.<p>
*
* the used formula is k = n! / (p1!*p2!+p3!*...*pn!) (see wiki)
*
* @param n the power of the (x1+x2+x3+...+xn)^n.
* @param powers [p1,p2,p3,...,pn] given in an array.
* @return the coefficient
*/
public static long coefficientMultinomialTheorem(int n, int[] powers)
{
// test is for checking if the coefficient exists
int test = 0;
long denominator = 1;
long numerator = 1;
// the faculty of the n
for(int i = 2; i <= n; ++i)
{
numerator *= i;
}
// the product of the faculties of the p's
for(int i = powers.length-1; i >= 0; --i)
{
// test, if the sum of all p's is bigger than the n
test += powers[i];
for(int j = 2; j <= powers[i]; ++j)
{
denominator *= j;
}
}
// is its bigger than the n, then there is no such element, thus the soefficient is zero
if(test != n)
return 0;
// return is n! / (p1!*p2!+p3!*...*pn!)
else
return numerator / denominator;
}

public static void main(String args[]) throws Exception
{
// generate Test Input
// int max = 13;
// for(int i = 1; i < max; ++i)
// {
// for(int j = 1; j < max; ++j)
// {
// System.out.print(i+" "+j+"\n");
// int[] array = new int[j];
// int sum = 0;
// for(int k = 0; k < j; ++k)
// {
// int number = (int) (Math.random()*j);
// if(sum + number <= j)
// {
// array[k] = number;
// sum += number;
// }
// if(k == j-1 && sum < j)
// {
// array[k] = j - sum;
// }
// }
// for(int k = 0; k < j; ++k)
// {
// System.out.print(array[k]);
// if(k < j-1)
// System.out.print(" ");
// }
// if(array.length > 0)
// System.out.print("\n");
// }
// }
BufferedReader reader= new BufferedReader(new InputStreamReader(System.in));
StringTokenizer token;
do
{
token = new StringTokenizer(reader.readLine());
int n = Integer.valueOf(token.nextToken());
int k = Integer.valueOf(token.nextToken());
int[] powers = new int[k];
if(k != 0)
token = new StringTokenizer(reader.readLine());
// the powers are read in the array
for(int i = 0; i < k; ++i)
{
powers[i] = Integer.valueOf(token.nextToken());
}
long coef = coefficientMultinomialTheorem(n, powers);
System.out.println(coef);
}
while(reader.ready());
}
}

5.

import java.io.*;
import java.util.StringTokenizer;

/**
* FWP, Angewandte Mathematik, SS11
* Problem: 10105 Polynomial Coefficients
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=13&page=show_problem&problem=1046
*
* @author Sebastian Stumpf
* @author Benjamin Vogt
* @version 1.0, 2011-05-29 09:39:09
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 0.376
*/
public class Main
{
/**
* returns the coefficient of a given x1^p1*x2^p2*x3^p3*...*xn^pn, using the multinpomial theorem.<p>
*
* the used formula is k = n! / (p1!*p2!+p3!*...*pn!) (see wiki)
*
* @param n the power of the (x1+x2+x3+...+xn)^n.
* @param powers [p1,p2,p3,...,pn] given in an array.
* @return the coefficient
*/
public static long coefficientMultinomialTheorem(int n, int[] powers)
{
// test is for checking if the coefficient exists
int test = 0;
long denominator = 1;
long numerator = 1;
// the faculty of the n
for(int i = 2; i <= n; ++i)
{
numerator *= i;
}
// the product of the faculties of the p's
for(int i = powers.length-1; i >= 0; --i)
{
// test, if the sum of all p's is bigger than the n
test += powers[i];
for(int j = 2; j <= powers[i]; ++j)
{
denominator *= j;
}
}
// is its bigger than the n, then there is no such element, thus the soefficient is zero
if(test != n)
return 0;
// return is n! / (p1!*p2!+p3!*...*pn!)
else
return numerator / denominator;
}

public static void main(String args[]) throws Exception
{
// generate Test Input
// int max = 13;
// for(int i = 1; i < max; ++i)
// {
// for(int j = 1; j < max; ++j)
// {
// System.out.print(i+" "+j+"\n");
// int[] array = new int[j];
// int sum = 0;
// for(int k = 0; k < j; ++k)
// {
// int number = (int) (Math.random()*j);
// if(sum + number <= j)
// {
// array[k] = number;
// sum += number;
// }
// if(k == j-1 && sum < j)
// {
// array[k] = j - sum;
// }
// }
// for(int k = 0; k < j; ++k)
// {
// System.out.print(array[k]);
// if(k < j-1)
// System.out.print(" ");
// }
// if(array.length > 0)
// System.out.print("\n");
// }
// }
BufferedReader reader= new BufferedReader(new InputStreamReader(System.in));
StringTokenizer token;
do
{
token = new StringTokenizer(reader.readLine());
int n = Integer.valueOf(token.nextToken());
int k = Integer.valueOf(token.nextToken());
int[] powers = new int[k];
if(k != 0)
token = new StringTokenizer(reader.readLine());
// the powers are read in the array
for(int i = 0; i < k; ++i)
{
powers[i] = Integer.valueOf(token.nextToken());
}
long coef = coefficientMultinomialTheorem(n, powers);
System.out.println(coef);
}
while(reader.ready());
}
}