母函数
#include<cstdio> #include<string.h> #define min(a,b) ((a)<(b)?(a):(b)) int N,v[26],n[26],a[55],b[55],i,j,k,last,last2,sum; int main() { scanf("%d",&N); while(N--){ for(i=0;i<26;++i){ scanf("%d",&n[i]); v[i]=i+1; } a[0]=1; last=0; for(i=0;i<26;++i){ last2=min(last+n[i]*v[i],50); memset(b,0,sizeof(int)*(last2+1)); for(j=0;j<=n[i]&&j*v[i]<=last2;++j) for(k=0;k<=last&&k+j*v[i]<=last2;++k) b[k+j*v[i]]+=a[k]; memcpy(a,b,sizeof(int)*(last2+1)); last=last2; } sum=0; for(i=1;i<=50;++i) sum+=a[i]; printf("%d\n",sum); } return 0; }