Codeforces Round #340 (Div. 2)B
1 second
256 megabytes
standard input
standard output
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.
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.
Print the number of ways to break the chocolate into multiple parts so that each part would contain exactly one nut.
3
0 1 0
1
5
1 0 1 0 1
4
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
题意 :一段01串 分割成段 每段只能有一个1 问一段串有多少种分割方式
题解:每两个1之间0的个数增加一的乘积
#include<bits/stdc++.h>
#define LL __int64
using namespace std;
LL n,l;
LL ans,k,flag;
int main()
{ l=0;
ans=1;
k=0;
scanf("%I64d",&n);
for(int i=1; i<=n; i++)
{
scanf("%I64d",&flag);
if(l)
{
k++;
if(flag)
{
ans*=k;
k=0;
}
}
if(flag)
l=1;
}
ans*=l;
printf("%I64d\n",ans);
}
Codeforces Round #340 (Div. 2)B的更多相关文章
- [Codeforces Round #340 (Div. 2)]
[Codeforces Round #340 (Div. 2)] vp了一场cf..(打不了深夜的场啊!!) A.Elephant 水题,直接贪心,能用5步走5步. B.Chocolate 乘法原理计 ...
- Codeforces Round #340 (Div. 2) E. XOR and Favorite Number 莫队算法
E. XOR and Favorite Number 题目连接: http://www.codeforces.com/contest/617/problem/E Descriptionww.co Bo ...
- Codeforces Round #340 (Div. 2) C. Watering Flowers 暴力
C. Watering Flowers 题目连接: http://www.codeforces.com/contest/617/problem/C Descriptionww.co A flowerb ...
- Codeforces Round #340 (Div. 2) B. Chocolate 水题
B. Chocolate 题目连接: http://www.codeforces.com/contest/617/problem/D Descriptionww.co Bob loves everyt ...
- Codeforces Round #340 (Div. 2) A. Elephant 水题
A. Elephant 题目连接: http://www.codeforces.com/contest/617/problem/A Descriptionww.co An elephant decid ...
- Codeforces Round #340 (Div. 2) D. Polyline 水题
D. Polyline 题目连接: http://www.codeforces.com/contest/617/problem/D Descriptionww.co There are three p ...
- 「日常训练」Watering Flowers(Codeforces Round #340 Div.2 C)
题意与分析 (CodeForces 617C) 题意是这样的:一个花圃中有若干花和两个喷泉,你可以调节水的压力使得两个喷泉各自分别以\(r_1\)和\(r_2\)为最远距离向外喷水.你需要调整\(r_ ...
- 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 ...
- 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 ...
- Codeforces Round #340 (Div. 2) E. XOR and Favorite Number (莫队)
题目链接:http://codeforces.com/contest/617/problem/E 题目大意:有n个数和m次查询,每次查询区间[l, r]问满足ai ^ ai+1 ^ ... ^ aj ...
随机推荐
- 前端开发工程师 - 03.DOM编程艺术 - 期末考试
期末考试客观题 返回 倒计时: 01:24 1 单选(2分) 以下选项中不是节点类型的是 A. COMMENT_NODE B. DOCUMENT_NODE C. BODY_NODE D. E ...
- javaScript中两个等于号和三个等于号之间的区别
一言以蔽之:==先转换类型再比较,===先判断类型,如果不是同一类型直接为false. ===表示恒等于,比较的两边要绝对的相同 alert(0 == ""); // trueal ...
- 4.安装hive
下载安装包并解压安装元数据库配置hive添加hvie环境变量修改hive-env.sh修改hive配置文件初始化metastore使用hive cli配置hivemestore配置hiveserv ...
- Python3 数据类型-字符串
字符串是 Python 中最常用的数据类型,是一个个字符组成的有序的序列,是字符的集合. 一 字符串定义 创建字符串很简单,可以使用引号('或"或""")来创建 ...
- SPOJ 694 Distinct Substrings/SPOJ 705 New Distinct Substrings(后缀数组)
Given a string, we need to find the total number of its distinct substrings. Input T- number of test ...
- UVALive 3668 A Funny Stone Game(博弈)
Description The funny stone game is coming. There are n piles of stones, numbered with 0, 1, 2,..., ...
- 小程序的picker的range 是一个 Object Array (对象数组)
小程序的picker的range 是一个 Object Array (对象数组) 数据: array: [{'id':1,'name':'Android'},{'id':2,'name':'IOS'} ...
- JS中Text节点总结
文本节点有Text类型表示,包含的是可以找字面解释的纯文本内容.纯文本中可以包含转移后的HTML字符,但不能包含HTML代码.Text节点具有以下属性: 1.nodeType的值为3. 2.nodeN ...
- 自测之Lesson15:TCP&UDP网络编程
题目:编写一个TCP通信的程序. 实现代码: #include <stdio.h> #include <sys/socket.h> #include <unistd.h& ...
- Thunder团队第六周 - Scrum会议4
Scrum会议4 小组名称:Thunder 项目名称:i阅app Scrum Master:胡佑蓉 工作照片: 苗威同学在拍照,所以不在照片内. 参会成员: 王航:http://www.cnblogs ...