01背包变形
(f(i, j) = f(i - 1, j) + f(i - 1, j - v[i]))
初始条件要注意:f[0~n][0] = 1;
代码
#include<iostream>
#include<vector>
using namespace std;
const int N = 110, M = 10010;
int f[M];
int n, m;
int v[N];
int main(){
cin >> n >> m;
for(int i = 1; i <= n; i ++) cin >> v[i];
f[0] = 1;
for(int i = 1; i <= n; i ++)
for(int j = m; j >= v[i]; j --)
f[j] += f[j - v[i]];
cout << f[m];
}