https://www.luogu.org/problem/P1164
idea
It’s easy to find that it’s a 01 bag problem ,
but I think my dp learned so nervous that meeting the easy change problem can’t get idea in a short time
after looking the problem solution , there is a very nice idea , use one Dimension(维度)to get answer, it’s better than other solution ,.
also the 01 bag Template(模板) the key is that , init the dp[0]=1!
then , dp[j]=dp[j-a[i]] !
it’s quite smart to use this Transfer equation(转移方程)
miaoa
anyway, I can’t write it in this way without help
AC Code
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
using namespace std;
int a[10005],dp[10005],ans;
int main(){
int n,num;
cin >> n >> num;
for(int i = 1;i <= n;i++){
cin >> a[i];
}
dp[0]=1;
for(int i = 1;i <= n;i++)
for(int j = num;j > 0;j--){
if(j>=a[i])
dp[j]+=dp[j-a[i]];
}
cout << dp[num] << endl;
}