Description
Bob loves everything sweet. He favorite chocolate bar consists of pieces, each piece may contain a nut. Bob wants to break the bar of chocolate into multiple pieces so, each part would contain exactly one nut and any b Reak line goes between, adjacent pieces.
You is asked to calculate the number of ways he can do it. Ways to break chocolate is considered distinct if one of them contains a break between some, adjacent pieces and T He other one doesn ' t.
Please note, if Bob doesn ' t do any breaks, all the bar would 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 Choco Late 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, each part would contain exactly one nut.
Sample Test (s)
input
3
0 1 0
Output
1
input
5
1 0 1) 0 1
Output
4
Note
In the first sample there are exactly one nut, so the number of ways equals 1-bob shouldn ' t do any breaks.
In the second sample can break the bar in four ways:
10|10|1
1|010|1
10|1|01
1|01|01
How to see it, first of all a block must have 1 to meet the requirements. 0 can be drawn to the left or right.
Then you can do that 10001
Divided into 1 0001;10 001; 100 01; 1000 1
If it is 1000100 ... No matter how many 0 back there, it's okay.
So it's 10001001. As in the first case, the first 10001 points and 1001 combinations are multiplied.
Note 000000 ... is equal to 0.
So we have to pay attention to 1 of the position, the 0 is divided on it.
#include <stdio.h>//#include <bits/stdc++.h> #include <string.h> #include <iostream> #include <math.h> #include <sstream> #include <set> #include <queue> #include <map> #include < vector> #include <algorithm> #include <limits.h> #define INF 0x3fffffff#define inf 0x3f3f3f3f#define Lson L,m,rt<<1#define Rson m+1,r,rt<<1|1#define LL long long#define ULL unsigned long longusing namespace Std;int m Ain () {int n; int a[1000]; LL Ans=1; int x=-1; cin>>n; for (int i=1;i<=n;i++) {cin>>a[i]; } for (int i=1;i<=n;i++) {if (A[i]) {x=i; Break }} if (X==-1) {cout<<0; return 0; } else {int i; int s=x; for (i=x+1;i<=n;i++) {if (A[i]) {ans*= (i-s); S=i; }//cout<<s<<endl; S=i; } cout<<ans<<endl; } return 0;}
Codeforces Round #340 (Div. 2) B