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

30 1 0

output

1

input

51 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;
}

  

时间: 2024-10-11 05:54:57

Codeforces Round #340 (Div. 2) B的相关文章

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

任意门:http://codeforces.com/problemset/problem/617/E E. XOR and Favorite Number time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output Bob has a favorite number k and ai of length n. Now he asks yo

Codeforces Round #340 (Div. 2) B. Chocolate

题意:一段01串 分割成段 每段只能有一个1 问一段串有多少种分割方式 思路:两个1之间有一个0就有两种分割方式,然后根据分步乘法原理来做. (不过这里有一组0 1 0这种数据的话就不好直接处理,所以遇到第一个1才开始标记) 1 #include<iostream> 2 using namespace std; 3 int main() 4 { 5 long long l=0; 6 int n; 7 cin>>n; 8 int a; 9 int j=0; 10 int s=0; 1

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

E. XOR and Favorite Number Bob has a favorite number k and ai of length n. Now he asks you to answer m queries. Each query is given by a pair li and ri and asks you to count the number of pairs of integers i and j, such that l ≤ i ≤ j ≤ r and the xor

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

题目大意:给你一个长度为n的序列,有m个询问,每次询问一个区间[L,R],表示这个区间内,有多少的a[i]^a[i+1].....^a[j]=k. 思路:莫队去搞就好了 我们定义pre[i]=a[1]^a[2]^....a[i],然后我们再去更新就好了,这里,我们定义区间[L,R]表示我们所要询问的区间即可.然后这里会有一个疑惑,就是为什么while(l<Q[i].l) { Delete(l-1); l++; }和while(l>Q[i].l) { l--; Updata(l-1); }是这样

Codeforces Round #279 (Div. 2) ABCD

Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name     A Team Olympiad standard input/output 1 s, 256 MB  x2377 B Queue standard input/output 2 s, 256 MB  x1250 C Hacking Cypher standard input/output 1 s, 256 MB  x740 D Chocolate standard input/

Codeforces Round #428 (Div. 2)

Codeforces Round #428 (Div. 2) A    看懂题目意思就知道做了 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i

Codeforces Round #424 (Div. 2) D. Office Keys(dp)

题目链接:Codeforces Round #424 (Div. 2) D. Office Keys 题意: 在一条轴上有n个人,和m个钥匙,门在s位置. 现在每个人走单位距离需要单位时间. 每个钥匙只能被一个人拿. 求全部的人拿到钥匙并且走到门的最短时间. 题解: 显然没有交叉的情况,因为如果交叉的话可能不是最优解. 然后考虑dp[i][j]表示第i个人拿了第j把钥匙,然后 dp[i][j]=max(val(i,j),min(dp[i-1][i-1~j]))   val(i,j)表示第i个人拿

Codeforces Round #424 (Div. 2) C. Jury Marks(乱搞)

题目链接:Codeforces Round #424 (Div. 2) C. Jury Marks 题意: 给你一个有n个数序列,现在让你确定一个x,使得x通过挨着加这个序列的每一个数能出现所有给出的k个数. 问合法的x有多少个.题目保证这k个数完全不同. 题解: 显然,要将这n个数求一下前缀和,并且排一下序,这样,能出现的数就可以表示为x+a,x+b,x+c了. 这里 x+a,x+b,x+c是递增的.这里我把这个序列叫做A序列 然后对于给出的k个数,我们也排一下序,这里我把它叫做B序列,如果我

[Codeforces] Round #352 (Div. 2)

人生不止眼前的狗血,还有远方的狗带 A题B题一如既往的丝帛题 A题题意:询问按照12345678910111213...的顺序排列下去第n(n<=10^3)个数是多少 题解:打表,输出 1 #include<bits/stdc++.h> 2 using namespace std; 3 int dig[10],A[1005]; 4 int main(){ 5 int aa=0; 6 for(int i=1;;i++){ 7 int x=i,dd=0; 8 while(x)dig[++dd