// Run time: 0.010
#include <stdio.h>
int arr[12];
double calculate(int n, int m);
int main()
{
int n, k;
int i;
double prod;
int sum;
while (scanf("%d%d", &n, &k) == 2)
{
prod = 1;
sum = 0;
for ( i = 0; i < k; i++)
scanf("%d", &arr[i]);
for ( i = 0; i < k; i++)
sum += arr[i];
if (sum > n)
{
printf("0\n");
continue;
}
for ( i = 0; i < k; i++)
{
prod *= calculate(n, arr[i]);
n -= arr[i];
}
printf("%.0lf\n", prod);
}
return 0;
}
double calculate(int n, int m)
{
int i, j;
double sum = 1;
if (2*m > n)
m = n-m;
for ( i = 0; i < m;)
sum *= double(n--)/double(++i);
return sum;
}
沒有留言:
張貼留言