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. 大神所写的深度好文---Gradle 构建工具

    什么是构建工具? 我们大家都知道 Gradle 是一种构建工具,那么什么是构建工具呢? 网上一大堆的文字解释我觉得很难理解,这里我以咱们 Android 开发来举个例子吧. 我们以前开发都是用 Ecl ...

  2. linux安装mysql可视化工具MySQL-workbench 连接数据库 执行sql

    Step1:建立数据库连接 点击新建连接的按钮,符号是“+”的按钮,出现下图,在“Connection name”输入连接名称. 填写连接信息 输入数据库连接密码 测试连接: 再次点击连接时会要求输入 ...

  3. 创建全局函数 匹配查找 std::map

    std::map<CString, CString> m_NameToType; 所有文件之外声明一个函数 在要用到的地方  加入存储的东西 extern std::map<CStr ...

  4. Python学习【第4篇】:Python之文件操作

    文件操作 读取一行 f=open("D:\\1.txt",'rb') print f.readline() f.close() 将文件内容保存在一个list with open(& ...

  5. 20180429NOIP提高组精英班Day1测试

  6. poj2385 - Apple Catching【动态规划】

    Description It is a little known fact that cows love apples. Farmer John has two apple trees (which ...

  7. SSH技术介绍和Xshell公钥远程登陆

    SSH简介 传统的网络服务程序,比如FTP,POP,Telnet,本质上都是不安全的,因为它们在网络上用明文传送数据.用户账号和用户口令,很容易受到中间人攻击方式的攻击,攻击者会冒充真正的服务器接收用 ...

  8. Map的两种遍历方式

    ********************************************************************************* ****************** ...

  9. RHEL6 配置Yum库

    在/mnt目录下创建子目录“/cdrom”(用于将iso文件挂载到此目录下) 镜像状态确定为“已连接”(“已连接”未勾选的情况下无法获得iso文件) 配置自动挂载文件 (系统开机时会主动读取“/etc ...

  10. 37.分组聚合操作—其他metric

    课程大纲     要学其他的metric(count,avg,max,min,sum) count:bucket,terms,自动就会有一个doc_count,就相当于是count avg:avg a ...