Title description:
Given VV currencies (unit: yuan), there is no limit to the number of times each currency can be used.
Different currencies may have the same face value.
Now, if you want to use this VV currency to collect NN yuan, how many different methods are there?
Input format
The first line contains two integers VV and NN.
The next few lines will output a total of VV integers, each of which represents the denomination of a currency.
Output format
Output an integer, representing the total number of solutions requested.
data range
1≤V≤251≤V≤25,
1≤N≤10000 1≤N≤10000 The
answer is guaranteed to be within the long long
range.
Input sample:
3 10
1 2 5
Sample output:
10
#include <iostream>
#include <cstdio>
using namespace std;
const int MAX = 10009;
typedef long long LL;
int n, m;
LL a[30][MAX];
int w[30];
int main()
{
scanf("%d%d", &n, &m);
a[0][0] = 1;
for(int i = 1; i <= n; i++)
scanf("%d", &w[i]);
for(int i = 1; i <= n; i++)
{
for(int j = 0; j <= m; j++)
{
for(int k = 0; k * w[i] <= j; k++)
a[i][j] += a[i - 1][j - k * w[i]]; // 面值为w[i]的选k个
}
}
printf("%lld\n", a[n][m]);
return 0;
}