题意:给你n个数,这些数可以互相加或者减,输出在范围【1,sum】里不能通过运算得出的数
思路:套母函数模版
#include <iostream>
#include<cstdio>
using namespace std;
#define N 110
int a[N],c1[10010],c2[10010],v[10010];
int main(int argc, char** argv) {
int n,sum,i,j,k,ans;
while(scanf("%d",&n)!=EOF){
sum=0;
ans=0;
for(i=0;i<n;i++){
scanf("%d",&a[i]);
sum+=a[i];
}
for(i=0;i<=sum;i++){
c1[i]=0;
c2[i]=0;
}
for(i=0;i<=a[0];i+=a[0])
c1[i]=1;
for(i=1;i<n;i++){
for(j=0;j<=sum;j++){
for(k=0;k+j<=sum&&k<=a[i];k+=a[i]){
if(k>=j)
c2[k-j]+=c1[j];
else
c2[j-k]+=c1[j];
c2[j+k]+=c1[j];
} }
for(j=0;j<=sum;j++){
c1[j]=c2[j];
c2[j]=0;
}
}
for(i=1;i<=sum;i++)
if(!c1[i])
v[ans++]=i; printf("%d\n",ans);
if(ans){
for(i=0;i<ans-1;i++)
printf("%d ",v[i]);
printf("%d\n",v[i]);
}
}
return 0;
}