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

时间:2022-10-27 23:43:38

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 水题的更多相关文章

  1. Codeforces Round &num;340 &lpar;Div&period; 2&rpar; A&period; Elephant 水题

    A. Elephant 题目连接: http://www.codeforces.com/contest/617/problem/A Descriptionww.co An elephant decid ...

  2. Codeforces Round &num;340 &lpar;Div&period; 2&rpar; D&period; Polyline 水题

    D. Polyline 题目连接: http://www.codeforces.com/contest/617/problem/D Descriptionww.co There are three p ...

  3. Codeforces Round &num;185 &lpar;Div&period; 2&rpar; B&period; Archer 水题

    B. Archer Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/312/problem/B D ...

  4. Codeforces Round &num;360 &lpar;Div&period; 2&rpar; A&period; Opponents 水题

    A. Opponents 题目连接: http://www.codeforces.com/contest/688/problem/A Description Arya has n opponents ...

  5. Codeforces Round &num;190 &lpar;Div&period; 2&rpar; 水果俩水题

    后天考试,今天做题,我真佩服自己... 这次又只A俩水题... orz各路神犇... 话说这次模拟题挺多... 半个多小时把前面俩水题做完,然后卡C,和往常一样,题目看懂做不出来... A: 算是模拟 ...

  6. Codeforces Round &num;256 &lpar;Div&period; 2&sol;A&rpar;&sol;Codeforces448A&lowbar;Rewards&lpar;水题&rpar;解题报告

    对于这道水题本人觉得应该应用贪心算法来解这道题: 下面就贴出本人的代码吧: #include<cstdio> #include<iostream> using namespac ...

  7. Codeforces Round &num;340 &lpar;Div&period; 2&rpar; B&period; Chocolate

    题意:一段01串 分割成段 每段只能有一个1 问一段串有多少种分割方式 思路:两个1之间有一个0就有两种分割方式,然后根据分步乘法原理来做. (不过这里有一组0 1 0这种数据的话就不好直接处理,所以 ...

  8. Educational Codeforces Round 13 C&period; Joty and Chocolate 水题

    C. Joty and Chocolate 题目连接: http://www.codeforces.com/contest/678/problem/C Description Little Joty ...

  9. Codeforces Round &num;338 &lpar;Div&period; 2&rpar; A&period; Bulbs 水题

    A. Bulbs 题目连接: http://www.codeforces.com/contest/615/problem/A Description Vasya wants to turn on Ch ...

随机推荐

  1. java并发编程实战(java concurrency in practice)

    第一章   线程共享进程范围内的资源,但每个线程都有各自的程序计数器.栈以及局部变量等. 多个线程可以同时调度到多个CPU上运行.   线程的优势? 在服务应用程序中,可以提升资源利用率以及系统吞吐率 ...

  2. python strip&lpar;&rpar; lstrip&lpar;&rpar; rstrip&lpar;&rpar; 使用方法

    Python中的strip用于去除字符串的首尾字符串,同理,lstrip用于去除最左边的字符,rstrip用于去除最右边的字符. 这三个函数都可传入一个参数,指定要去除的首尾字符. 需要注意的是,传入 ...

  3. JAVA基础知识之JVM-——类加载器

    类加载器负责将.class文件加载到内存,并为其创建java.lang.Class对象,这个对象就代表这个类. 在Java中,通过包名+类名来唯一标识一个类,而在JVM中,要用 类加载器实例+包名+类 ...

  4. DELL服务器SAS 5 I&lowbar;R 完全配置手册

    http://wenku.baidu.com/view/f258a36eb84ae45c3b358c55.html?re=view

  5. IO (二)

    1 字符流的缓冲区 缓冲区的出现提高了对数据的读写效率. 对应的类: BufferedWriter BufferedReader 缓冲区要结合流才能使用. 在流的基础上对流的功能进行了增强. 2 Bu ...

  6. C&num;实现完整的防盗自制监控系统

    在您的手机中通知您家中的入侵者,并拍摄他们的照片 介绍 在本文中,我将展示一些DIY东西​​,用于安装监控系统,检测家中的入侵者,拍摄照片并通过手机通知您,必要时可以打电话给警察并提供照片以便快速识别 ...

  7. 想拥有自己的Python程序包,你只需15步

    来源商业新知网,原标题:15步,你就能拥有自己的Python程序包 全文共 3192 字,预计学习时长 6 分钟 每个软件开发员和数据科学家都难免要做程序包.本文推荐一篇 Python开源程序包的制作 ...

  8. 【出错记录】Tomcat非root用户启动无法拥有权限读写文件

    简单记录下,如有必要,将深入补充: 一.非root用户运行Tomcat及原因 由于项目中,为了安全需要,Tomcat将禁止以root形式启动,原因很简单,举个例子,一旦有人恶意将jsp文件透过某个别的 ...

  9. 20165203 《网络对抗技术》week1 Kali的安装与配置

    20165203 <网络对抗技术>week1 Kali的安装与配置 本人感觉Kali可以做很多有意思的事情,下面是本人的Kali的安装过程. 安装过程 光盘映像文件的下载 登录官网,选择下 ...

  10. webdriver 启动chrome时加载配置

    Selenium操作浏览器是不加载任何配置的,网上找了半天,关于Firefox加载配置的多点,Chrome资料很少,下面是关于加载Chrome配置的方法:  一.加载所有Chrome配置 用Chrom ...