暴力枚举。
1 #include<cstdio> 2 #include<algorithm> 3 using namespace std; 4 int n,a[101],sum[101],half,ans; 5 int query(const int &A,const int &B) 6 { 7 int x=max(A,B),y=min(A,B),res=sum[x-1]-sum[y-1]; 8 if(res>half) return sum[n]-res; 9 else return res; 10 } 11 int main() 12 { 13 scanf("%d",&n); 14 for(int i=1;i<=n;i++) 15 { 16 scanf("%d",&a[i]); 17 sum[i]=sum[i-1]+a[i]; 18 } 19 half=sum[n]>>1; 20 for(int i=1;i<=n;i++) 21 for(int j=i+1;j<=n;j++) 22 for(int k=j+1;k<=n;k++) 23 for(int l=k+1;l<=n;l++) 24 if(query(i,j)==query(k,l)&&query(j,k)==query(l,i)) 25 ans++; 26 printf("%d ",ans); 27 return 0; 28 }