这题做的我欲哭无泪啊……
我已经没心情多说啥了……
高精度T啊!我太弱啊!改了一天啊!还不如滚粗啊!
想好式子在写啊!
能用高精度乘单精度就不要用高精度乘高精度啊!
能用高精度除单精度就不要用高精度除高精度啊!
T成翔啊!
简单的组合计数问题啊!
题解在这里=_= : http://www.cnblogs.com/zhj5chengfeng/archive/2013/08/23/3278557.html
上代码:
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cmath>
#define N 1100
using namespace std; class bignum
{
public:
int l;
int num[N*];
bignum(int nownum)
{
memset(num, , sizeof(num)); l = ;
if (nownum == ) l = ;
else while (nownum)
{
num[++l] = nownum % ;
nownum /= ;
}
}
void jia(int y);
void chu(int y);
void cheng(int y);
void print();
};
int n, d[N], sum = ; void bignum::jia (int y)
{
num[] += y; int d = num[] / ; int i = ;
while (d)
{
num[++i] = d;
d = num[i] / ;
num[i] %= ;
}
if (i > l) l = i;
} void bignum::cheng (int y)
{
for (int i = ; i <= l; ++i)
num[i] = num[i] * y;
int d = ;
for (int i = ; i <= l; ++i)
{
num[i] += d;
d = num[i] / ;
num[i] %= ;
}
while (d)
{
num[++l] = d;
d = num[l] / ;
num[l] %= ;
}
while (l > && num[l] == ) l--;
} void bignum::chu (int y)
{
int yu = ;
for (int i = l; i >= ; --i)
{
yu = yu* + num[i];
num[i] = yu / y;
yu %= y;
}
while (l > && num[l] == ) l --;
} void bignum::print()
{
int d = ;
for (int i = ; i <= l; ++i)
{
num[i] += d;
d = num[i] / ;
num[i] %= ;
}
while (d) { num[++l] += d; d = num[l] / ; num[l] %= ; }
for (int i = l; i >= ; --i) printf("%d", num[i]);
printf("\n"); return;
} int main()
{
scanf("%d", &n); int fre = ;
for (int i = ; i <= n; ++i)
{
scanf("%d", &d[i]);
if (d[i] != -) { fre++; sum += d[i]-; }
}
if (sum > n-)
{
printf("0\n");
return ;
}
bignum ans = ;
for (int i = n--sum; i <= n-; ++i) ans.cheng(i);
for (int i = ; i <= n-sum-; ++i) ans.cheng(n-fre);
for (int i = ; i <= n; ++i)
if (d[i] > )
for (int j = ; j < d[i]; ++j) ans.chu(j);
ans.print();
return ;
}