### Saratov State University :: Online Contester

::Go
- home
- news
- register
 - update personal info
 - problemset archive
- submit
- status online
- standing
- contests
- virtual contests
- forum
- statistic
- FAQ
- projects

 ::Poll Are you registered on Codeforces?YesNoWhat is it???[results]

::webboard

Author: paunmatei7
ID: 059022
Problem: 269
Contest: 0
Date: 2013-08-01 18:40:12

#include<stdio.h>
#include<string.h>
#include<algorithm>

#define NMAX 257

using namespace std;

int a[NMAX];
int n, k;
short int D[NMAX][NMAX][NMAX], aux[NMAX];

void adun(short int aa[] , short int bb[]){
int i,t=0;
aa[0] = max(aa[0], bb[0]);
for (i=1;i<=aa[0];i++){
aa[i]+=bb[i]+t;
t=aa[i]/10;
aa[i]%=10;
}
if (t)
aa[++aa[0]]=t;
}

void prod(short int h[], int x){
int t=0;
for(int i = 1; i <= h[0]; ++ i){
h[i] *= x;
h[i] += t;
t = h[i] / 10;
h[i] %= 10;
}
while (t)
h[++ h[0]] = t % 10, t /= 10;
}

int main(){
scanf("%d %d", &n, &k);
for(int i = 1; i <= n; ++ i)
scanf("%d", &a[i]);
sort(a + 1, a + n + 1);
/**D[0][0] = 1;
for(int i = 0; i < n; ++ i)
for(int j = 0; j <= k; ++ j)
D[i + 1][j] += D[i][j], D[i + 1][j + 1] += D[i][j] * (a[i + 1] - j);
printf("%lld", D[n][k]);*/
D[0][0][0] = D[0][0][1] = 1;
for(int i = 0; i < n; ++ i)
for(int j = 0; j < k; ++ j){
memset(aux, 0, sizeof(aux));
memcpy(aux, D[i][j], sizeof(aux));
prod(aux, a[i + 1] - j);
adun(D[i + 1][j + 1], aux);
}
for(int i = D[n][k][0]; i >= 1; -- i)
printf("%d", D[n][k][i]);
printf("n");
return 0;
}