嘿嘿,还是比较基本的母函数
/* ID: nanke691 LANG: C++ TASK: money */ #include<iostream> #include<string> #include<fstream> #include<string.h> #include<algorithm> using namespace std; const int maxn = 10000; int p[30],V,n; long long num1[maxn+1],num[maxn+1]; void sovle() { memset(num,0,sizeof(num)); memset(num1,0,sizeof(num1)); for(int i=0;i*p[0]<=n;i++) num1[i*p[0]]=num[i*p[0]]=1; for(int i=1;i<V;i++) { for(int j=1;j*p[i]<=n;j++) for(int k=0;k<=n;k++) { if(num[k]==0) continue; int t=k+j*p[i]; if(t>n)break; num1[t]+=num[k]; } for(int j=0;j<=n;j++) num[j]=num1[j]; } } int main() { freopen("money.in","r",stdin); freopen("money.out","w",stdout); cin>>V>>n; for(int i=0;i<V;i++) cin>>p[i]; sovle(); cout<<num[n]<<endl; return 0; }