Beispiel #1
0
//	Returns the total number of polynomial terms (coefficients) not including the additive constant for a polynomial of rank
//	Rank defined over an Ndims dimensional space.  If N is not null, it must point to a pre-allocated vector of length Rank.
//	On output, each N[i] will contain the number of (i+1)-order terms for a polynomial defined over an Ndims-dimensional space.
//		e.g. N[0]  Returns the number of first order ("linear") terms when Rank>=1 (this is always equal to Ndims).
//		e.g. N[1]  Returns the number of second order ("quadratic") terms when Rank>=2
//		e.g. N[2]  Returns the number of third order ("cubic") terms when Rank>=3
//		etc...
//	This function's return value is equal to the sum of elements in N.
int Ncoeff(int* N, int Rank, int Ndims)
{	
	//	Indexors
	int i;
	//	If 0-dimensionality, set everything to empty.
	if( Ndims<=0 )
	{
		if( N!=null )
		{
			for(i=0; i<Rank; i++)
				N[i] = 0;
		}
		return 0;
	}
	//	If there is no rank, return 0.
	if (Rank<=0)
		return 0;
	//	Return linear terms.
	if( Rank==1)
	{
		//	The number of linear terms is always Ndims
		if (N != null)
			N[0] = Ndims;
		return Ndims;
	}
	//	Compute the number of inhomogeneous polynomial terms for the given rank and dimensionality.
	int output = Pascal(Rank,Ndims);
	
	//	Subtract 1 to remove the 0-th order term.
	output--;
	
	//mexPrintf("Pascal(%i,$i)=%i\n",Rank,Ndims,output);
	
	//	Fill output vector N and sum to compute output.
	if (N != null)
	{
		N[0] = Ndims;  //	There are Ndims linear terms
		//mexPrintf("N[0]=%i\n", Ndims);
		for( i=1; i<Rank; i++)
		{
			N[i] = Pascal(i+1,Ndims-1);
			//mexPrintf("N[%i]=%i\n", i, N[i]);
		}
	}

	//	Return value.
	return output;
}
 int main(void)
 {
     int t,n,m,N,r,i,players,flag;
     Pascal();
     scanf("%d",&t);
     //printf("%llu",ncr[4][2]);

     while(t--)
     {
         for(i=0;i<=100;i++)
            a[i]=0;
         for(i=1;i<=11;i++)
            {scanf("%d",&n);
              a[n]++;
             }
             scanf("%d",&m);
             players=0;
             flag=0;

            for(i=100;i>=1;i--)
            {
                if(a[i])
                {
                    //printf("!%d,%d!",i,a[i]);
                    players=players+a[i];
                    if(players>m)
                    {
                        players=players-a[i];
                        r=m-players;
                        N=a[i];
                        // printf("~%d,%d~",N,r);
                        flag=1;
                        break;
                    }
                    if(players==m)
                        break;
                }
            }
            if(flag)
            printf("%llu\n",ncr[N][r]);
            else
                printf("1\n");
     }
     return 0;
}