[Title] effect
Given n positive integers $ A_1, A_2, ..., An $, so to choose the number and several m, there are many choices for the program requirements.
[Resolved] ideas
Really is a typical 0/1 knapsack problem the board, where the only change is not asking this question the most value, but several programs, so a slight change transfer equation.
【Code】
1 #include<bits/stdc++.h> 2 #define rg register 3 #define go(i,a,b) for(rg int i=a;i<=b;i++) 4 #define back(i,a,b) for(rg int i=a;i>=b;i--) 5 #define ll long long 6 using namespace std; 7 const int N=102,M=10002; 8 int n,m,a[N]; 9 ll f[M]; 10 int main(){ 11 scanf("%d%d",&n,&m); 12 go(i,1,n) scanf("%d",&a[i]); 13 memset(f,0,sizeof(f)); 14 f[0]=1; 15 go(i,1,n) back(j,m,a[i]) 16 f[j]+=f[j-a[i]]; 17 printf("%lld\n",f[m]); 18 return 0; 19 }