Codeforces Round #340 (Div. 2) B

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Round #340 (Div. 2) B相关的知识,希望对你有一定的参考价值。

Description

Bob loves everything sweet. His favorite chocolate bar consists of pieces, each piece may contain a nut. Bob wants to break the bar of chocolate into multiple pieces so that each part would contain exactly one nut and any break line goes between two adjacent pieces.

You are asked to calculate the number of ways he can do it. Two ways to break chocolate are considered distinct if one of them contains a break between some two adjacent pieces and the other one doesn‘t.

Please note, that if Bob doesn‘t make any breaks, all the bar will form one piece and it still has to have exactly one nut.

Input

The first line of the input contains integer n (1 ≤ n ≤ 100) — the number of pieces in the chocolate bar.

The second line contains n integers ai (0 ≤ ai ≤ 1), where 0 represents a piece without the nut and 1 stands for a piece with the nut.

Output

Print the number of ways to break the chocolate into multiple parts so that each part would contain exactly one nut.

Sample test(s)
input
3
0 1 0
output
1
input
5
1 0 1 0 1
output
4
Note

In the first sample there is exactly one nut, so the number of ways equals 1 — Bob shouldn‘t make any breaks.

In the second sample you can break the bar in four ways:

10|10|1

1|010|1

10|1|01

1|01|01

怎么看呢,首先一个分块必须有1才符合要求。0可以划到左边或者右边。

那么 可以这样 10001

分为  1  0001;10 001 ; 100 01; 1000 1

如果是1000100 。。。  后面不管有多少0都没关系啦

那么是10001001 呢。和第一种情况一样 先分10001 再分1001 组合就是乘起来。

注意000000...是等于0的

所以我们要注意1的位置,对0进行划分就可以了。

#include<stdio.h>
//#include<bits/stdc++.h>
#include<string.h>
#include<iostream>
#include<math.h>
#include<sstream>
#include<set>
#include<queue>
#include<map>
#include<vector>
#include<algorithm>
#include<limits.h>
#define inf 0x3fffffff
#define INF 0x3f3f3f3f
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define ULL unsigned long long
using namespace std;
int main()
{
    int n;
    int a[1000];
    LL ans=1;
    int x=-1;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    for(int i=1;i<=n;i++)
    {
        if(a[i])
        {
            x=i;
            break;
        }
    }
    if(x==-1)
    {
        cout<<0;
        return 0;
    }
    else
    {
    int i;
    int s=x;
    for(i=x+1;i<=n;i++)
    {
        if(a[i])
        {
           ans*=(i-s);
           s=i;
        }
      //  cout<<s<<endl;
       // s=i;
    }
    cout<<ans<<endl;
    }
    return 0;
}

  

以上是关于Codeforces Round #340 (Div. 2) B的主要内容,如果未能解决你的问题,请参考以下文章

莫队 Codeforces Round #340 (Div. 2) E

Codeforces Round #340 (Div. 2) E. XOR and Favorite Number 莫队算法

Codeforces Round #340 (Div. 2) E. XOR and Favorite Number 莫队算法

Codeforces Round #340 (Div. 2) E XOR and Favorite Number 莫队板子

Codeforces Round #340 (Div. 2) E. XOR and Favorite Number 莫队算法 + 异或和前缀和的巧妙

Codeforces Round #436 E. Fire(背包dp+输出路径)