nguyentranbathuanlh
Rating
-
Bài tập
4
Điểm
3535
Rating #
-
Điểm #
11157
Giới thiệu
include<bits/stdc++.h>
define maxn 10005
define ll long long
define vec vector
define pb push_back
define str string
define fi first
define se second
using namespace std;
int n,a[maxn],sum;
bool f[101][100000];
vec<int> result;
void nhap(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i]; sum+=a[i];
}
for(int i=0;i<=n;i++) f[i][0]= true;
}
void xuly(){
for(int i=1;i<=n;i++){
for(int j=1;j<=sum;j++){
f[i][j]=f[i-1][j];
if(f[i][j]==false&&j>=a[i]){
f[i][j]=f[i-1][j-a[i]];
}
}
}
for(int j=1;j<=sum;j++){
if (f[n][j]) result.pb(j);
}
cout<<result.size()<<endl;
for(auto x:result) cout<<x<<" ";
}
int main(){
// freopen("tester.inp","r",stdin);
// freopen("tester.out","w",stdout);
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
nhap();
xuly();
}