标签:hdu1261
#include <stdio.h> #include <string.h> const int MAX =505; struct BigNum { int num[MAX]; int len; } a[51][51]; BigNum Div(BigNum &a, int &b) { BigNum c; int f; int i, len = a.len; memset(c.num, 0, sizeof(c.num)); f = 0; for(i = a.len-1; i >= 0; i--) { f = f*10+a.num[i]; c.num[i] = f/b; f %= b; } while(len > 1 && c.num[len-1] == 0) len--; c.len = len; return c; } BigNum Mul1(BigNum &a, int &b) { BigNum c; int i, len; len = a.len; memset(c.num, 0, sizeof(c.num)); //乘以0,直接返回0 if(b == 0) { c.len = 1; return c; } for(i = 0; i < len; i++) { c.num[i] += (a.num[i]*b); if(c.num[i] >= 10) { c.num[i+1] = c.num[i]/10; c.num[i] %= 10; } } while(c.num[len] > 0) { c.num[len+1] = c.num[len]/10; c.num[len++] %= 10; } c.len = len; return c; } int main() { BigNum sum; int i,j,m,p[26],s; while(scanf("%d",&m),m) { s=0; memset(p,0,sizeof(p)); for(i=0; i<m; i++) { scanf("%d",&p[i]); s+=p[i]; } for(i=1; i<MAX; i++) sum.num[i]=0; sum.num[0]=1; sum.len=1; for(i=2; i<=s; i++) sum=Mul1(sum,i); for(i=0; i<m; i++) for(j=2; j<=p[i]; j++) sum=Div(sum,j); for(i=sum.len-1; i>=0; i--) printf("%d",sum.num[i]); printf("\n"); } return 0; }
标签:hdu1261
原文地址:http://blog.csdn.net/fei____fei/article/details/25147631