这动规没见过,不好做……参考题解了……
https://www.luogu.org/blog/DEDSECspace/solution-p1164
https://www.luogu.org/blog/6-28318530717958/solution-p1164
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | #include<iostream> #include<algorithm> #include<cstdio> #include<string> #include<deque> #include<map> #include<cstring> using namespace std; int n, m; int A[105]; int f[10005]; int main() { cin >> n >> m; for (int i = 1; i <= n; i++)cin >> A[i]; f[0] = 1; for (int i = 1; i <= n; i++) { for (int j = m; j >= A[i]; j--) { f[j]+= f[j - A[i]]; } } cout << f[m]; } |