/* * Calculates the matrix that transforms a B-spline basis to a power basis * Input: p (degree of basis) * Output: M (power matrix) */ DenseMatrix getBSplineToPowerBasisMatrix1D(unsigned int p) { assert(p > 0); // m = n+p+1 // M is a lower triangular matrix of size (p+1)x(p+1) DenseMatrix M; M.setZero(p+1,p+1); for (unsigned int j = 0; j <= p; j++) // cols { for (unsigned int i = j; i <= p; i++) // rows { M(i,j) = pow(-1,i-j)*binomialCoeff(p,j)*binomialCoeff(p-j,i-j); } } return M; }
int main() { int n,k,t; scanf("%d",&t); while(t--) { scanf("%d%d",&n,&k); printf("%lld\n",binomialCoeff(n+k-1,n-1)); } return 0; }
/* * Calculates the reparameterization matrix that changes the domain of a basis * Input: p (degree of basis), a (left bound/first knot), b (right bound/last knot) * Output: Rinv (reparameterization matrix that changes the domain from [0,1] to [a,b]) */ DenseMatrix getReparameterizationMatrix1D(int p, double a, double b) { assert(p > 0 && a < b); // R is a upper triangular matrix of size (p+1)x(p+1) DenseMatrix R; R.setZero(p+1,p+1); for (int i = 0; i <= p; i++) // rows { for (int j = i; j <= p; j++) // cols { R(i,j) = binomialCoeff(j,i)*pow(b-a,i)*pow(a,j-i); } } return R; }
// This function returns an array of nCm integers. In each integer, exactly m bits are 1. int *subsets(int n, int m) { int maxsubsetindex; // maximum subset index int count; int shiftedx; int c,C; int *subsetlist; if(m>n) { printf("\n\nError: m must be less than or equal to n.\n\n"); return(NULL); } if( n >= 8*sizeof(int)) { printf("\n\nError: n must be less than %d.\n\n",8*sizeof(int)); return(NULL); } maxsubsetindex = (int)pow(2.0,1.0*n)-1; C = binomialCoeff(n,m); subsetlist = (int *)calloc(C,sizeof(int)); c = 0; for(int x=0; x<=maxsubsetindex; x++) { count=0; for(int i=0; i<n; i++) { shiftedx = x >> i; count += (shiftedx & 1); } if(count==m) subsetlist[c++]=x; } return(subsetlist); }
int main(){ int n,k; scanf("%d%d",&n,&k); printf("%d",binomialCoeff(n,k)); return 0; }