//[3/17/2015 jmings]/* This problem can be deduced directly from the formula:{(a1+a2+......+an)! {a1! A2!...... an!}
because (12x26)! = 312! can only be stored through an array, so it involves "large number multiplication" and "large number division", the main idea of large number realization simulation hand calculation, specific reference program. */
1#include <iostream>2#include <cstdlib>3#include <cstdio>4#include <cstring>5 using namespacestd;6 Const intMAX = -;7 8 intN, arr[ -];9 intTotal ;Ten intAns[max], Len; One A //factorial - voidFactorial (int_n,int_arr[],int&_len) { - for(intnum =2; Num <= _n; ++num) { the intCNT =0, val, carry =0; - for(CNT < _len; + +)CNT) { -val = _arr[cnt] * num +carry; -_ARR[CNT] = val%Ten; +Carry = val/Ten; - } + while(carry) { A_arr[_len++] = carry%Ten; atCarry/=Ten; - } - } - } - - //Large Number Division in voidDiv (intdata) { - intcarry =0; to intVal; + for(inti = len-1; I >=0; --i) { -val = ans[i] + carry *Ten; theAns[i] = val/data; *carry = val%data; $ }Panax Notoginseng while(0= = Ans[len-1]) { ---Len; the } + } A the voidSolve () { + for(inti =0; I < n; ++i) { - for(intj =2; J <= Arr[i]; ++j) { $ Div (j); $ } - } - } the - intMain ()Wuyi { the //freopen ("Input.txt", "R", stdin); - //freopen ("Output.txt", "w", stdout); Wu while(~SCANF ("%d", &n) &&N) { -Total =0; About for(inti =0; I < n; ++i) { $scanf"%d", &arr[i]); -Total + =Arr[i]; - } -ans[0] =1; ALen =1; + factorial (total, Ans, Len); the Solve (); - for(inti = len-1; I >=0; --i) { $printf"%d", Ans[i]); the } theprintf"\ n"); the } the return 0; -}
Combination Math + large number multiplication + large number of divisions HDU 1261 strings