Chocolate

Time Limit: 1000MS

  Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u

Submit
Status

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 Input

Input
3
0 1 0
Output
1
Input
5
1 0 1 0 1
Output
4

Sample Output

Hint

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

Source


两个1之间有几种选择,然后连乘,跟组合数思想是一样的


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int a[110],b[110];
int main()
{
int n;
while(cin>>n)
{
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
__int64 ans=1;
int k=0;
for(int i=1;i<=n;i++)
{
cin>>a[i];
if(a[i])
b[k++]=i;
}
if(k==0)
cout<<0<<endl;
else if(k==1)
cout<<1<<endl;
else
{
for(int i=1;i<k;i++)
ans=ans*(b[i]-b[i-1]);
cout<<ans<<endl;
}
}
return 0;
}

Codeforces--617B--Chocolate(规律)的更多相关文章

  1. codeforces 617B Chocolate

    题意: 在给定01串中,问能分割成多少个子串?每个子串只有一个1. dp #include<iostream> #include<string> #include<alg ...

  2. Codeforces 617B:Chocolate(思维)

    题目链接http://codeforces.com/problemset/problem/617/B 题意 有一个数组,数组中的元素均为0或1 .要求将这个数组分成一些区间,每个区间中的1的个数均为1 ...

  3. codeforces 362A找规律

    刚开始以为是搜索白忙活了原来是个简单的找规律,以后要多想啊 此题是两马同时跳 A. Two Semiknights Meet time limit per test 1 second memory l ...

  4. codeforces——思路与规律

    codeforces 804B     http://codeforces.com/problemset/problem/804/B /* 题意:给定一个只含ab的序列,每次操作可将ab变为bba 问 ...

  5. Codeforces 490D Chocolate

    D. Chocolate time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  6. CodeForces 598E Chocolate Bar

    区间DP预处理. dp[i][j][k]表示大小为i*j的巧克力块,切出k块的最小代价. #include<cstdio> #include<cstring> #include ...

  7. Nastya and a Wardrobe CodeForces - 992C(规律)

    写一下二叉树  推一下公式就出来了, 注意取模时的输出形式 #include <bits/stdc++.h> #define mem(a, b) memset(a, b, sizeof(a ...

  8. Codeforces 145A-Lucky Conversion(规律)

    A. Lucky Conversion time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  9. codeforces D. Queue 找规律+递推

    题目链接: http://codeforces.com/problemset/problem/353/D?mobile=true H. Queue time limit per test 1 seco ...

  10. Codeforces Round #340 (Div. 2) B. Chocolate 水题

    B. Chocolate 题目连接: http://www.codeforces.com/contest/617/problem/D Descriptionww.co Bob loves everyt ...

随机推荐

  1. Android开发笔记(8)——调用子Activity

     转载请注明:http://www.cnblogs.com/igoslly/p/6853730.html  调用子Activity 需要子Activity返回值 MainActivity使用start ...

  2. webstorm中配置过visualsvn,后面做更改要更换authentication realm的解决办法

    找这个找了好久,一直改不过来,终于找到了解决办法 首先,在提交代码时提示: 但是我的authentication realm已经时这个了,并且账号和密码也改了,所以要更改authentication ...

  3. C# 字符串的入门

    1."@"表示字符串中的"\"不当成转义符. 2.转义符或者特殊处理的一些字符只是针对于代码中直接写出的字符串中,对于程序运行中读取出来的转义符或者特殊处理的字 ...

  4. 3.用Redis Desktop Manager连接Redis(CentOS)

    Redis Desktop Manager是Redis图形化管理工具,方便管理人员更方便直观地管理Redis数据. 然而在使用Redis Desktop Manager之前,有几个要素需要注意: 一. ...

  5. Power Designer逆向操作(从mysql5.0生成数据库的物理模型)

    Power Designer逆向操作(从mysql5.0生成数据库的物理模型) 环境:powderdesigner12.5:mysql5.0 步骤: 1.  为指定的数据库配置MySQL的ODBC数据 ...

  6. java_File对象

    package File; import java.io.File; import java.io.IOException; public class file { public static voi ...

  7. log4net 局部代码 看不懂....

    public interface ILogger {} public interface ILoggerWrapper { ILogger Logger {get;} } public interfa ...

  8. Promise嵌套问题/async await执行顺序

    /* 原则: 执行完当前promise, 会把紧挨着的then放入microtask队尾, 链后面的第二个then暂不处理分析, */ 一. new Promise((resolve, reject) ...

  9. https webservice通讯 参考网址 http://blog.csdn.net/small____fish/article/details/8214938

    一.生成密钥库和证书可参考以下密钥生成脚本,根据实际情况做必要的修改,其中需要注意的是:服务端的密钥库参数“CN”必须与服务端的IP地址相同,否则会报错,客户端的任意. 1.生成服务器证书库keyto ...

  10. 【模板】最小生成树Kruskal

    洛谷3366 #include<cstdio> #include<algorithm> using namespace std; ,maxm=; ,ans=; struct e ...