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. 基于TensorFlow的车牌号识别系统

    简介 过去几周我一直在涉足深度学习领域,尤其是卷积神经网络模型.最近,谷歌围绕街景多位数字识别技术发布了一篇不错的paper.该文章描述了一个用于提取街景门牌号的单个端到端神经网络系统.然后,作者阐述 ...

  2. 删除过期备份报错RMAN-06207 RMAN-06208解决方案

    RMAN备份日志中出现了警告 日志文件目录如下: [root@erpdbs rmanback]# ll total 88 -rw-r--r-- 1 oraprod dba 81011 Sep 7 22 ...

  3. Android studio在使用过程中的问题总汇!

    使用android studio也有一段时间了,汇总了一下这段时间内遇到一些常见问题,希望能够帮助到大家! 一.字体大小问题 在android studio的使用过程中没有发现类似于Eclipse中的 ...

  4. JAVA和JVM运行原理揭秘

    这里和大家简单分享一下JAVA和JVM运行的原理,Java语言写的源程序通过Java编译器,编译成与平台无关的‘字节码程序’(.class文件,也就是0,1二进制程序),然后在OS之上的Java解释器 ...

  5. 批量注释LOG

    sed -i "s/LOG/\/\/ LOG/g" `grep LOG\(TRACE\) -rl .`

  6. hibernate Hql 更新的参数只能设置String类型

    最近在项目中发现一个奇怪的现象,请看下面的代码 实体类MyEmployeeEntity @Table(name="myemployee") public class MyEmplo ...

  7. transition-分栏按钮动画

      => css: .cateBtn{ position: relative; background: #fff; border: 1px solid #ddd; border-radius: ...

  8. 【Android】进程间通信IPC——Binder

    Binder是Android中的跨进程通信方式,bindService的时候,服务端返回Binder对象,通过该对象客户端可以从服务端获取数据.在进程间通信IPC——AIDL中创建了ICustomAi ...

  9. Vi/Vim基本用法

    Vi/Vim是Linux中一款功能强大的编辑器,vi是Visual Interface的缩写,即可视化接口,vim是vi iMprove的缩写,即 vi的增强版(具有语法着色功能).它在Linux上的 ...

  10. 创建broker配置

    1.准备工作 ■ 创建oracle11g的primary和standby库,物理standby,最大性能模式 ■ DG_BROKER_START设置为TRUE 2.创建broker配置 DGMGRL& ...