本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作。
N<= 20
//It is made by ljh2000
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long LL;
const int MAXN = 45;
int n,a[MAXN],tot,sum,ans;
inline int getint(){
int w=0,q=0; char c=getchar(); while((c<‘0‘||c>‘9‘) && c!=‘-‘) c=getchar();
if(c==‘-‘) q=1,c=getchar(); while (c>=‘0‘&&c<=‘9‘) w=w*10+c-‘0‘,c=getchar(); return q?-w:w;
}
inline void work(){
n=getint(); for(int i=1;i<=n;i++) a[i]=getint(),sum+=a[i];
if(sum&1){ printf("0"); return ; } sum>>=1;
for(int i=1,j=1;i<n;i++) { tot+=a[i]; while(tot>sum) tot-=a[j++]; if(tot==sum) ans++; }
printf("%d",ans*(ans-1)/2);
}
int main()
{
work();
return 0;
}
原文:http://www.cnblogs.com/ljh2000-jump/p/6238742.html