Address:
Click to open the link
Interesting, for this topic, the array I opened is not big enough, and it actually gave me TE.
The most interesting thing about this topic is that both sides can be placed, that is, the following a[kl] and a[k+l] need to be assigned.
code show as below:
#include<iostream> #include<cstdio> #include<string.h> #include<cmath> #include<stdlib.h> #include<fstream> using namespace std; #define MAX 10100 int n ,w[101],a[MAX],b[MAX],res[MAX]; int main(){ int i,j,k,Num,SUM,res_num; while(~scanf("%d",&Num)) { SUM = 0 ; memset(res,0,sizeof(res)); memset(w,0,sizeof(w)); memset(a,0,sizeof(a)); for(i = 1 ; i<= Num; i ++) { scanf("%d",&w[i]); SUM+=w[i]; } a[0]=a[w[1]]=1; memset(b,0,sizeof(b)); for(i = 2 ; i <= Num ; i++) { for(j = 0; j <=SUM ; j++) { for(k = 0 ; k<=w[i]&&k+j<=SUM ; k+=w[i]) { b[j+k]+= a[j]; b[abs(j-k)]+=a[j] ; } } for(j = 0 ; j <=SUM; j++) { a[j]=b[j]; b[j]=0 ; } } res_num=0; for(i = 1 ; i <=SUM ; i++) { if(a[i]==0) { res [res_num ++] = i; } } printf("%d\n",res_num); if(res_num>0) { printf("%d",res[0]); for(i = 1 ; i <res_num ; i++) { printf(" %d",res[i]); } printf("\n"); } } }