link:
https://www.acwing.com/problem/content/280/
Meaning of the questions:
Given N positive integers A1, A2, ..., AN, to choose the number of the plurality, and that their is M, ask how many there are options.
Ideas:
backpack.
Code:
#include <bits/stdc++.h>
using namespace std;
int a[110], Dp[10010];
int n, m;
int main()
{
scanf("%d%d", &n, &m);
for (int i = 1;i <= n;i++)
scanf("%d", &a[i]);
Dp[0] = 1;
for (int i = 1;i <= n;i++)
{
for (int j = m;j >= a[i];j--)
Dp[j] += Dp[j-a[i]];
}
printf("%d\n", Dp[m]);
return 0;
}