题目链接:http://codeforces.com/problemset/problem/687/C点击打开链接
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <stdio.h>
#include <string.h>
#include <set>
using namespace std;
vector< int >s;
set<int > ans;
set<int > ::iterator it;
int dp[555][555];
int main()
{
int n,m;
cin >> n >> m;
for(int i=1;i<=n;i++)
{
int mid;
cin >> mid;
s.push_back(mid);
}
dp[0][0]=1;
for(int i=0;i<s.size();i++)
for(int j=m;j>=0;j--)
for(int k=j;k>=0;k--)
{
if(j>=s[i])
dp[j][k]=dp[j][k]||dp[j-s[i]][k];
if(k>=s[i])
dp[j][k]=dp[j][k]||dp[j-s[i]][k-s[i]];
}
for(int i=0;i<=m;i++)
if(dp[m][i])
ans.insert(i);
cout << ans.size() << endl;
for(it=ans.begin();it!=ans.end();it++)
cout << (*it) << " ";
}