Codeforces 617B Chocolate
来源:互联网 发布:史丹利快报的淘宝店 编辑:程序博客网 时间:2024/04/20 03:00
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.
30 1 0
1
51 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
恩,果然判了特例就过了。
特例 :
输入:
3
0 0 0
输出:
0
#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<stack>#include<queue>using namespace std;int main(){ int n,t; __int64 sum; while(~scanf("%d",&n)) { sum=1; int cnt=0,flag=0,sign=0; for(int i=0;i<n;++i) { scanf("%d",&t); if(t==1) sign=1; if(t==0&&flag) cnt++; else if(t==1&&flag) { sum*=(cnt+1); cnt=0; } else if(t==1) flag=1; } if(!sign) sum=0; printf("%I64d\n",sum); } return 0;}
- Codeforces 617B Chocolate
- CodeForces 617B Chocolate
- CodeForces 617B-chocolate
- Codeforces 617B Chocolate 【dp】
- Codeforces Problem - 617B Chocolate
- Codeforces 617B Chocolate【思维】
- CodeForces 617 B. Chocolate(组合数学)
- CodeForces - 617B Chocolate (规律)
- Codeforces--617B--Chocolate(规律)
- Codeforces 617B Chocolate (Round #340 (Div. 2) B题)
- CodeForces 617B B. Chocolate【计数+累乘】
- Codeforces Round #340-B. Chocolate-水+坑
- Codeforces Round #340 (Div. 2):B. Chocolate
- B. Chocolate
- Codeforces Jzzhu and Chocolate
- CodeForces 490D Chocolate
- codeforces 490 D Chocolate
- Codeforces Round #340 (Div. 2)-B. Chocolate(组合数学的乘法计数)
- AFNetworking 原作者都无法解决的问题: 如何使用ip直接访问https网站?
- Codeforces 617C Watering Flowers 【暴力 数据范围】
- Java 包
- c中定义变量的内存分配顺序问题(极易错!!!)
- Codeforces 617A Elephant
- Codeforces 617B Chocolate
- Codeforces D Polyline
- C++链表
- HDOJ 5611 Baby Ming and phone number
- 咱码农为啥会(珍爱生命)远离企业应用开发
- HDOJ 5610 Baby Ming and Weight lifting
- UVa 489 Hangman Judge
- 领导喜欢什么样的人
- 前些日子读了《杜拉拉升职记》