#1475: Array splitting

Source: Internet
Author: User
Tags gcd

#1475: Array split time limit: 10000ms single point time limit: 1000ms memory limit: 256MB description

Little Ho got an array as a gift for his new year, and he liked this array very much!

After a few days of careful study, small Ho succeeded in splitting the array into segments, and each paragraph was not 0!

Now little Ho would like to know how many of these splitting methods are there?

The two split methods are treated differently when and only if the array is made up of all the locations where the arrays are broken.

Input

The first behavior of each set of inputs is a positive integer n, which indicates the length of the array

The second behaves n integers a1~an, describing the array that little Ho received

For 40% of data, meet 1<=n<=10

For 100% of data, meet 1<=n<=105, | ai|<=100

Output

For each set of inputs, the output is one line of ans, which represents the remainder of the split scheme divided by (109+7).

Sample input
51-1 0 2-2
Sample output
5
Analysis: Dp[i] Represents the previous I number scheme, Sum[i] represents the prefix and I;
DP[I]=∑DP[J] (1<=j<i)-∑dp[k] (1<=k<i&&sum[k]==sum[i]);
Code:
#include <iostream>#include<cstdio>#include<cstdlib>#include<cmath>#include<algorithm>#include<climits>#include<cstring>#include<string>#include<Set>#include<bitset>#include<map>#include<queue>#include<stack>#include<vector>#defineRep (I,m,n) for (i=m;i<=n;i++)#defineMoD 1000000007#defineINF 0x3f3f3f3f#defineVI vector<int>#definePB Push_back#defineMP Make_pair#defineFi first#defineSe Second#definell Long Long#definePi ACOs (-1.0)#definePII pair<int,int>#defineSYS system ("pause")Const intmaxn=1e5+Ten;Const intn=1e3+Ten;using namespacestd;ll gcd (ll p,ll q) {returnq==0? P:GCD (q,p%q);} ll Qpow (ll p,ll q) {ll F=1; while(q) {if(q&1) f=f*p;p=p*p;q>>=1;}returnF;}intn,m,k,t,a[maxn];ll Sum,dp[maxn];map<int,ll>p;intMain () {inti,j; p[0]=1; scanf ("%d",&N); Rep (I,1, N) scanf ("%d", &a[i]), a[i]+=a[i-1]; Rep (I,1, N) {Dp[i]+=sum+1; Dp[i]-=P[a[i]]; (Dp[i]+=MOD)%=MoD; Sum+=Dp[i]; Sum%=MoD; P[a[i]]+=Dp[i]; P[a[i]]%=MoD; } printf ("%lld\n", Dp[n]); return 0;}

#1475: Array splitting

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.