我有这个代码:
#include<iostream>
#include<algorithm>
#define mod 1000000007
using namespace std;
unsigned long long int pow(int);
unsigned long long int binomialCoeff(int ,int );
int i,j;
int T[1000][1000];
int main()
{
unsigned long long int t,k,n,ans;
cin>>t;
while(t--)
{
ans=0;
cin>>n;
int a[n];
for(i=0;i<n;i++)
cin>>a[i];
if(n%2==0)
ans=(pow(n-1)-((binomialCoeff(n,n/2))/2))%mod;
else
ans=pow(n-1)%mod;
printf("%lld\n",ans);
}
system("pause");
}
unsigned long long int binomialCoeff(int na,int rb)
{
for(i=0;i<na-rb+1;i++)
**T[i,0]=1;**
for(i=0;i<rb+1;i++)
**T[i,i]=1;**
for(j=1;j<rb+1;j++)
{
for(i=j+1;i<na-rb+j+1;i++)
**T[i,j]=T[i-1,j-1]+T[i-1,j];**
}
return (T[na,rb]);
}
unsigned long long int pow(int n)
{
int k;
if(n==0)
return 1;
else if(n%2==0)
{k=pow(n/2);return ((k%mod)*(k%mod))%mod;}
else
{k=pow(n/2);return ((((k%mod)*(k%mod))%mod)*2)%mod;}
}
我有这个算法:
2^(n-1) - ((1+(-1)^n)/4)*binomial(n, n/2)
...对于这个问题。
但是在我的编译器中,我遇到了编译错误:
In function `long long unsigned int binomialCoeff(int, int)':
incompatible types in assignment of `int' to `int[1000]'
invalid operands of types `int[1000]' and `int[1000]' to binary `operator+'
invalid conversion from `int*' to `long long unsigned int'