Files
python/C++专题课程/动态规划/动态规划-7-和为SUM的方法数.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

30 lines
502 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include<bits/stdc++.h>
using namespace std;
/*
知识点内容:和为sum的方法数
文档内容参考:
https://www.cnblogs.com/aiguona/p/9218754.html
*/
int main() {
int n, sum;
cin >> n >> sum;
vector<long long> a(sum + 1);
vector<int> b(n);
for (int i = 0; i < n; i++)
cin >> b[i];
a[0] = 1;
for (int i = 0; i < n; i++)
for (int j = sum; j >= b[i]; j--)
a[j] += a[j - b[i]];
cout << a[sum] << endl;
return 0;
}