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 ...
随机推荐
- Dapper的完整扩展(转)
真心想说:其实...我不想用Dapper,如果OrmLite.Net支持参数化的话,也就没Dapper的什么事情了,对于OrmLite.Net只能做后续跟踪...... 这个其实是看了Dapper作者 ...
- Tesseract-OCR识别验证码
1. 安装Tesseract-OCR,安装后测试下是否安装成功
- 推荐一款C#反编译软件(开源)
大二的时候老师要求做过一个小项目,大概4个人左右一组.当时交流不是特别到位,项目在一个同学的电脑上建成了就一直在他的电脑上(所以好东西不要烂在你的硬盘里),也不知道什么源码管理,可悲到项目做完我还没有 ...
- 使用curl操作openstack swift
openstack官网有专门的开发者文档介绍如何使用curl操作swift(http://docs.openstack.org/api/openstack-object-storage/1.0/con ...
- 《Genesis-3D开源游戏引擎--横版格斗游戏制作教程08:虚拟键盘实现》--本系列完结
8.虚拟键盘实现 概述: 硬键盘就是物理键盘,平时敲的那种.软键盘是虚拟的键盘,不是在键盘上,而是在"屏幕"上.虚拟按键就是虚拟键盘的一部分,根据功能需求,提供部分按键效果的UI可 ...
- php 的简单易用的调式方法,打印方法
简单的调试方法:echo, print_r, var_dump, exit, debug_backtrace(), debug_print_backtrace(), gettype(), get_cl ...
- U盘分区信息清除
diskpart select disk 1 clean 清除选中(优U)盘的所有信息;
- 【多线程】Java线程面试题 Top 50(转载)
Java线程面试题 Top 50 原文链接:http://www.importnew.com/12773.html 本文由 ImportNew - 李 广 翻译自 javarevisited.欢迎 ...
- VoHelper
VoHelper package com.isoftstone.pcis.policy.core.helper; import com.isoftstone.fwk.dao.CommonDao; im ...
- 规范打log
在公司工作快3年了,debug用的最多的还是分析程序打出来的log. 怎样打log,打什么样的log,也是很值得研究的事情.好的打log方式,能够很快的分析和解决问题. 下面总结两点: 1.在log中 ...