Hihocoder 1475 number of components dismantled

Source: Internet
Author: User

#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 

first think O (n^2) dp,dp[i] + = Dp[j], j < i && sum[i]! = Sum[j] Br> optimization can get an O (n) algorithm, plus minus.


//http://www.cnblogs.com/imgavin///https://hihocoder.com/problemset/ Problem/1475#include <iostream> #include <stdio.h> #include <cstdlib> #include <cstring># Include <queue> #include <vector> #include <map> #include <stack> #include <set> #include <bitset> #include <algorithm>using namespace std;typedef long LL; #define gets (a) fgets (A, 1e8, stdin) const int INF = 0x3f3f3f3f, N = 100008, MOD = 1000000007;const int M = 20000008;const int P = 1e7;const double EPS = 1e-6; int a[n]; LL Dp[n]; LL Ds[n]; LL sum[n];int tot = 0;int s2[m];int main () {int n;cin >> n;for (int i = 1; I <= N; i++) {scanf ("%d", &a[i]); sum[ I] = Sum[i-1] + a[i];} Dp[0] = 1;ds[0] = 1;s2[10000000] = 1;for (int i = 1; I <= n; i++) {Dp[i] = (ds[i-1]-s2[sum[i] + 10000000] + MOD)% MO D; (S2[sum[i] + 10000000] + + dp[i])%= mod;ds[i] = (Ds[i-1] + dp[i])% MOD; Cout<<dp[n]<<endl;return 0;} 

  



Hihocoder 1475 number of components dismantled

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.