是个天平 可以相减,
#include <iostream>
#include <cstdio>
using namespace std;
const int maxn = 10100;
int c1[maxn], c2[maxn];
int num[101], f[maxn];
int n;
int main()
{
while(cin >> n)
{
int sum = 0;
for(int i = 1; i <= n; i++)
{
scanf("%d", &num[i]);
sum += num[i];
}
for(int i = 0; i <= sum; i++)
{
c1[i] = 0;
c2[i] = 0;
}
c1[0] = c1[num[1]] = 1;
for(int i = 2; i <= n; i++)
{
for(int j = 0; j <= sum; j++)
for(int k = 0; k+j <= sum && k <= num[i]; k += num[i])
{
if(j >= k) c2[j-k] += c1[j];
else c2[k-j] += c1[j];
c2[k+j] += c1[j];
}
for(int j = 0; j <= sum; j++)
{
c1[j] = c2[j];
c2[j] = 0;
}
}
int k = 0;
for(int i = 0; i <= sum; i++)
if(c1[i]==0) f[k++] = i;
if(k)
{
printf("%d\n", k);
for(int i = 0; i < k-1; i++)
printf("%d ", f[i]);
printf("%d\n", f[k-1]);
}
else printf("0\n");
}
}