Codeforces Round #340 (Div. 2) B. Chocolate 水题
2016-01-24 23:17
309 查看
B. Chocolate
题目连接:
http://www.codeforces.com/contest/617/problem/DDescriptionww.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
51 0 1 0 1
Sample Output
4Hint
题意
给你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; }
相关文章推荐
- Efficient Graph-Based Image Segmentation解读
- 打印super_block结构中的一些域的值
- Codeforces Round #329 (Div. 2) D. Happy Tree Party(树链剖分)
- 自定义Directive使用ngModel
- 面向对象程序设计 ——第一次作业
- kuangbin_SegTree A (HDU 1166)
- BigDecimal用法详解
- 2015年大二上-数据结构-图-1-(4)-利用遍历思想求解图问题(2)
- printf的输出相关
- HDOJ 2043 密码
- POJ1833 排列
- 自创建内容提供其provider的权限问题
- 观察者模式(observer)
- Android基础_3 Activity相对布局
- A + B问题(字符串与数字之间的转换)
- OC基础(三)get/set/. @proterty和@synthesize关键字等使用
- Leetcode 235 Lowest Common Ancestor of a Binary Search Tree 二叉树
- Selective Search for Object Recognition解读
- 线程_总结JAVA183
- junit(七)