https://codeforces.com/contest/466/problem/C
题目大意:
数组a由n个整数组成a[1],a[2],...,a[n]。计算将数组中的所有元素分成三个连续部分的方法,以使每个部分中的元素总和相同,求数量。
智慧数据
input
6
0 0 1 -1 0 0
output
6
不必dp,贪心即可
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18;
const LL N=500200,M=2002;
//unordered_map<LL,LL> a[N];
//priority_queue<LL> pq;
//priority_queue<LL,vector<LL>,greater<LL>> pq2;
LL a[N],b[N]={0};
int main()
{
cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
LL T=1;
//cin>>T;
while(T--)
{
LL n;
cin>>n;
LL sum=0;
for(int i=1;i<=n;i++)
{
cin>>a[i];
sum+=a[i];
}
if(sum%3!=0) cout<<"0"<<endl;
else
{
LL flag=0,sum1=0,ans=0;
for(int i=1;i<n;i++)
{
sum1+=a[i];
//第二节
if(sum1==(2*sum)/3) ans+=flag;
//第一节
if(sum1==sum/3) flag++;
//cout<<flag<<" "<<ans<<endl;
}
cout<<ans<<endl;
}
}
return 0;
}
标签:const,Ways,LL,Codeforces,cin,Number,dp
From: https://www.cnblogs.com/Vivian-0918/p/17037865.html