Codeforces Round #340 (Div. 2) B. Chocolate 水题
B. Chocolate
题目连接:
http://www.codeforces.com/contest/617/problem/D
Descriptionww.co
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
5
1 0 1 0 1
Sample Output
4
Hint
题意
给你n个数字,你可以从数字间切开
然后问你有多少种切法,使得切出来的每一块恰有且仅有一个1
题解:
假如没有1,答案就是0
否则就是间隔中的0的个数+1的累乘
因为你就只能切0周围的空隙,然后根据乘法原则
代码
#include<bits/stdc++.h>
using namespace std;
int a[120];
vector<int> E;
int main()
{
int n;scanf("%d",&n);
int flag = 1;
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
if(a[i]==1)flag = 0;
}
if(flag)return puts("0");
int cnt = 0;
for(int i=1;i<=n;i++)
{
if(a[i]==1)
{
E.push_back(cnt+1);
cnt = 0;
}
else
cnt++;
}
long long ans = 1;
for(int i=1;i<E.size();i++)
ans = ans * E[i];
cout<<ans<<endl;
}
Codeforces Round #340 (Div. 2) B. Chocolate 水题的更多相关文章
- 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 ...
- Codeforces Round #185 (Div. 2) B. Archer 水题
B. Archer Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/312/problem/B D ...
- Codeforces Round #360 (Div. 2) A. Opponents 水题
A. Opponents 题目连接: http://www.codeforces.com/contest/688/problem/A Description Arya has n opponents ...
- Codeforces Round #190 (Div. 2) 水果俩水题
后天考试,今天做题,我真佩服自己... 这次又只A俩水题... orz各路神犇... 话说这次模拟题挺多... 半个多小时把前面俩水题做完,然后卡C,和往常一样,题目看懂做不出来... A: 算是模拟 ...
- Codeforces Round #256 (Div. 2/A)/Codeforces448A_Rewards(水题)解题报告
对于这道水题本人觉得应该应用贪心算法来解这道题: 下面就贴出本人的代码吧: #include<cstdio> #include<iostream> using namespac ...
- Codeforces Round #340 (Div. 2) B. Chocolate
题意:一段01串 分割成段 每段只能有一个1 问一段串有多少种分割方式 思路:两个1之间有一个0就有两种分割方式,然后根据分步乘法原理来做. (不过这里有一组0 1 0这种数据的话就不好直接处理,所以 ...
- Educational Codeforces Round 13 C. Joty and Chocolate 水题
C. Joty and Chocolate 题目连接: http://www.codeforces.com/contest/678/problem/C Description Little Joty ...
- Codeforces Round #338 (Div. 2) A. Bulbs 水题
A. Bulbs 题目连接: http://www.codeforces.com/contest/615/problem/A Description Vasya wants to turn on Ch ...
随机推荐
- WCF:百度百科
百科-WCF http://baike.baidu.com/view/1140438.htm Wcf Windows Communication Foundation(WCF)是由微软发展的一组数据通 ...
- head 命令
head 与 tail 就像它的名字一样的浅显易懂,它是用来显示开头或结尾某个数量的文字区块,head 用来显示档案的开头至标准输出中,而 tail 想当然尔就是看档案的结尾. 1.命令格式: hea ...
- 利用DescriptionAttribute定义枚举值的描述信息 z
System.ComponentModel命名空间下有个名为DescriptionAttribute的类用于指定属性或事件的说明,我所调用的枚举值描述信息就是DescriptionAttribute类 ...
- GIT 命令 操作 记录
1.git pull时冲突的解决 1.git stash 2.git pull 3.git stash pop stash@{0} 4.修改冲突 5.git add . 6.git commit 7. ...
- [转]linux之more命令
转自:http://www.cnblogs.com/peida/archive/2012/11/02/2750588.html more命令,功能类似 cat ,cat命令是整个文件的内容从上到下显示 ...
- php 高效分页
mysql.php 获取数据库中的记录,完全个人经验总结,仅供参考!<?php/***PHP+MYSQL数据库基本功能*http://blog.csdn.net/yown*/########## ...
- Chapter7:类
关于this指针 成员函数通过一个名为this的额外的隐式参数来访问调用它的对象.当我们调用一个成员函数时,用请求该函数的对象初始化this. total.isbn(); //等价于编译器重写为 Sa ...
- 判断是否为BST
递归的方法,用返回false的方法.中序遍历的想法很好,空间浪费.遍历的过程记录上一次的值进行比较. //题目描述 // //请实现一个函数,检查一棵二叉树是否为二叉查找树. //给定树的根结点指针T ...
- BitmapData类介绍
今天介绍另外一个比较常用和中高级难度的类:BitmapData 用好这个类,可以说是半支脚踏入了Flash高手的大门···(主要是不是太多的人精通这个··呵呵··)我也可以趁这篇文章的机会好好巩固+学 ...
- Chef
Chef是一个渐渐流行的部署大.小集群的自动化管理平台.Chef可以用来管理一个传统的静态集群,也可以和EC2或者其他的云计算提供商一起使用.Chef用cookbook作为最基本的配置单元,可以被泛化 ...