标签:
Description
Input
Output
Sample Input
Sample Output
#include"iostream" #include"cstring" using namespace std; int a[101]; int book[10001],ans[10001]; int m,n; void Work() { for(int i=0;i<n;i++) for(int j=m;j>=a[i];j--) { book[j]=min(book[j],book[j-a[i]]); } for(int i=0;i<n;i++) for(int j=0;j<=m-a[i];j++) { book[j]=min(book[j],book[j+a[i]]); } int top=0; for(int i=1;i<=m;i++) if(book[i]==1) ans[top++]=i; cout<<top<<endl; if(top) { for(int j=0;j<top-1;j++) cout<<ans[j]<<" "; cout<<ans[top-1]<<endl; } } int main() { while(cin>>n) { m=0; memset(book,0,sizeof(book)); for(int i=0;i<n;i++) {cin>>a[i];m+=a[i];} for(int j=1;j<=m;j++) book[j]=1; book[0]=0; Work(); } return 0; }
标签:
原文地址:http://www.cnblogs.com/zsyacm666666/p/4726425.html