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. 【转】升级还是权谋?从USB PD 2.0到3.0

    原文出处 http://www.eetop.cn/blog/html/43/n-433743.html 如同iPhone的出现,才让智能机真正主导手机市场一样,Type-C口发布后,USB PD才正式 ...

  2. JS——正则

    正则的声明: 1.构造函数:var 变量名= new RegExp(/表达式/); 2.直接量:var 变量名= /表达式/; test()方法: 1.正则对象方法,检测测试字符串是否符合该规则,返回 ...

  3. ddrmenu

    <%@ Register TagPrefix="dnn" TagName="MENU" Src="~/DesktopModules/DDRMen ...

  4. C语言保留字

    数值变量相关: int float double char long short unsigned signed 储存说明符 const 用于声明常量 static用于限制变量/函数的作用范围等等 e ...

  5. STL_优先队列_(转载)

    转自:http://www.cnblogs.com/summerRQ/articles/2470130.html STL容器之优先队列 优先级队列,以前刷题的时候用的比较熟,现在竟然我只能记得它的关键 ...

  6. centOS7创建python虚拟环境

    参考: 非常棒的2篇博客 https://www.centos.bz/2018/05/centos-7-4-%E5%AE%89%E8%A3%85python3%E5%8F%8A%E8%99%9A%E6 ...

  7. python 单元测试中处理用例失败的情况

    今天有一个需求, 在单元测试失败的时候打印一些日志, 我们管他叫 dosomething 吧 ,反正就是做一些操作 查了下并没有查到相关的方法, 于是研究了一波unittest 的源码 发现了这个东西 ...

  8. Luogu P2866 [USACO06NOV]糟糕的一天Bad Hair Day

    P2866 [USACO06NOV]糟糕的一天Bad Hair Day 题目描述 Some of Farmer John's N cows (1 ≤ N ≤ 80,000) are having a ...

  9. ORM 进阶操作

    ORM多表操作 一.创建模型 作者模型:一个作者有姓名和年龄. 作者详细模型:把作者的详情放到详情表,包含生日,手机号,家庭住址等信息:作者详情模型和作者模型之间是一对一的关系. 出版商模型:出版商有 ...

  10. Asp.NET误人子弟教程:在MVC里面结合JQ实现AJAX

    public class Person { public string Name { get; set; } public string City { get; set; } public strin ...