Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int n, sum = 0;
- int main(){
- ios::sync_with_stdio(false);
- cin.tie(nullptr);
- cin >> n;
- int a[n];
- for(int i = 0; i < n; i++) {
- cin >> a[i];
- sum+=a[i];
- }
- bool dp[sum+1];
- memset(dp, 0, sizeof(dp));
- dp[0] = 1;
- dp[sum] = 1;
- for(int i = 0; i < n; i++){
- for(int j = sum-1; j >= a[i]; j--)
- {
- if(dp[j-a[i]]) dp[j]=1;
- }
- }
- cout << count(dp + 1, dp + sum + 1, 1) << "\n";
- for(int i = 1; i <= sum; i++)
- if(dp[i]) cout << i << " ";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement