You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
python/C++专题课程/动态规划/动态规划-7-和为SUM的方法数.cpp

30 lines
473 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#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;
}