我正在尝试使用 dp 在 c 中计算 ncr(combinations)。但它在 n=70 时失败了。任何人都可以帮忙吗?
unsigned long long ncr( int n , int r)
{
unsigned long long c[1001];
int i=1;
c[0]=1;
for(i=1; i<=r; i++)
c[i]= ((unsigned long long) (c[i-1]) * (unsigned long long)( n-i+1))%(unsigned long long) (1000000007)/ (unsigned long long)(i);
return c[r];
}
基本思想是 ncr = ((n-r+1)/r)* nc(r-1)