http://oj.acm.zstu.edu.cn/JudgeOnline/problem.php?id=4261
题解:变形01背包问题
背包问题:https://blog.csdn.net/weixin_43272781/article/details/83214622
当放第i个数字x时,我们询问当前容量j,在j-x的数量,那么可以构成j的数量就是dp[j]本来的数量加上dp[j-x]的数量
/*
*@Author: STZG
*@Language: C++
*/
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
//#define DEBUG
#define RI register int
using namespace std;
typedef long long ll;
//typedef __int128 lll;
const int N=100000+10;
const int MOD=1e9+7;
const double PI = acos(-1.0);
const double EXP = 1E-8;
const int INF = 0x3f3f3f3f;
int t,n,m,k,q,ans;
int a[N];
int dp[N];
char str;
int main()
{
#ifdef DEBUG
freopen("input.in", "r", stdin);
//freopen("output.out", "w", stdout);
#endif
while(~scanf("%d%d",&n,&m)){
memset(dp,0,sizeof(dp));
dp[0]=1;
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
for(int j=m;j>=a[i];j--){
if(dp[j-a[i]])
dp[j]=dp[j-a[i]]+dp[j];
}
}
cout << dp[m]<< endl;
}
//cout << "Hello world!" << endl;
return 0;
}