HDU 1261. 排列组合+打表+高精度乘除法
原题链接
中等
作者:
史一帆
,
2021-04-09 21:09:54
,
所有人可见
,
阅读 233
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
int num[30];
vector<string> facs;
string div(const string &A, int b)
{
string s = "";
int c = 0, t = 0;
for (int i = 0; i < A.size(); i ++)
{
c = t * 10 + (A[i] - '0');
t = c % b;
c /= b;
if (c == 0 && s.size() == 0) continue;
else s += (c + '0');
}
return s;
}
string mul(const string &A, int b)
{
string s = "";
int c = 0, t = 0;
for (int i = A.size() - 1; i >= 0; i --)
{
c = (A[i] - '0') * b + t;
s += (c % 10 + '0');
t = c / 10;
}
while (t)
{
c = t % 10;
s += (c + '0');
t /= 10;
}
reverse(s.begin(), s.end());
return s;
}
void cal()
{
facs.push_back("0");
facs.push_back("1");
facs.push_back("2");
string tmp = "2";
for (int i = 3; i <= 26 * 12; i ++)
{
tmp = mul(tmp, i);
facs.push_back(tmp);
}
}
int main()
{
cal();
int n;
while (cin >> n && n)
{
string A = "";
int sum = 0;
for (int i = 1; i <= n; i ++)
{
cin >> num[i];
sum += num[i];
}
A = facs[sum];
for (int i = 1; i <= n; i ++)
for (int j = 2; j <= num[i]; j ++)
A = div(A, j);
cout << A << endl;
}
return 0;
}