• LQDOJ
  • Trang chủ
  • Bài tập
  • Bài nộp
  • Thành viên
  • Kỳ thi
  • Nhóm
  • Giới thiệu
    • Status
    • Khóa học
    • Đề xuất ý tưởng
    • Proposal Problem
    • Proposal Contest
    • Tools
    • Báo cáo tiêu cực
    • Báo cáo lỗi

Tiếng Việt

Tiếng Việt
English

Đăng nhập

Đăng ký

nguyentranbathuanlh

  • Giới thiệu
  • Bài tập
  • Bài nộp

Rating
-
Bài tập
4
Điểm
6273
Rating #
-
Điểm #
18141

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();
}


«    »
Thứ 2
Thứ 3
Thứ 4
Thứ 5
Thứ 6
Thứ 7
CN
Ít
Nhiều

proudly powered by DMOJ| developed by LQDJudge team