题目链接http://codeforces.com/problemset/problem/617/B

题意

有一个数组,数组中的元素均为0或1 。要求将这个数组分成一些区间,每个区间中的1的个数均为1。问有多少种分法

思路

将数组中的0全部去掉,用一个数组记录原数组中的每个1的位置,相邻的两个1的位置差为两个1之间的0的个数,让这些0的个数一次相乘就行了。但是要注意原数组中全是0的情况,还要注意数据类型,会爆int

AC代码

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <limits.h>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <string>
#define ll long long
#define ms(a) memset(a,0,sizeof(a))
#define pi acos(-1.0)
#define INF 0x3f3f3f3f
const double E=exp(1);
const int maxn=1e6+10;
using namespace std;
int a[maxn];
int main(int argc, char const *argv[])
{
int n;
cin>>n;
int x;
int j=0;
for(int i=0;i<n;i++)
{
cin>>x;
if(x==1)
a[++j]+=i;
}
ll ans=1;
if(j==0)
cout<<"0"<<endl;
else
{
for(int i=1;i<j;i++)
{
ans=ans*(a[i+1]-a[i]);
}
cout<<ans<<endl;
}
return 0;
}

Codeforces 617B:Chocolate(思维)的更多相关文章

  1. codeforces 617B Chocolate

    题意: 在给定01串中,问能分割成多少个子串?每个子串只有一个1. dp #include<iostream> #include<string> #include<alg ...

  2. CodeForces 604C 【思维水题】`

    题意: 给你01字符串的长度再给你一个串. 然后你可以在这个串中选择一个起点和一个终点使得这个连续区间内所有的位取反. 求: 经过处理后最多会得到多少次01变换. 例如:0101是4次,0001是2次 ...

  3. Minimum Integer CodeForces - 1101A (思维+公式)

    You are given qq queries in the following form: Given three integers lili, riri and didi, find minim ...

  4. Codeforces 1038D - Slime - [思维题][DP]

    题目链接:http://codeforces.com/problemset/problem/1038/D 题意: 给出 $n$ 个史莱姆,每个史莱姆有一个价值 $a[i]$,一个史莱姆可以吃掉相邻的史 ...

  5. AND Graph CodeForces - 987F(思维二进制dfs)

    题意:给出n(0≤n≤22)和m,和m个数ai,1 ≤ m ≤ 2n ,0≤ai<2n ,把ai & aj == 0 的连边,求最后有几个连通块 解析:一个一个去找肯定爆,那么就要转换一 ...

  6. CodeForces - 631C ——(思维题)

    Each month Blake gets the report containing main economic indicators of the company "Blake Tech ...

  7. Almost Acyclic Graph CodeForces - 915D (思维+拓扑排序判环)

    Almost Acyclic Graph CodeForces - 915D time limit per test 1 second memory limit per test 256 megaby ...

  8. Diagonal Walking v.2 CodeForces - 1036B (思维,贪心)

    Diagonal Walking v.2 CodeForces - 1036B Mikhail walks on a Cartesian plane. He starts at the point ( ...

  9. Codeforces 490D Chocolate

    D. Chocolate time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

随机推荐

  1. English trip -- VC(情景课)8 C

    MP review: 音标(Phonetic symbol) [ɪ]    lit adj. 照亮的,点着的(light的过去式及过去分词)n. (Lit)人名:(瑞典)利特:(老)李 [ʊ]   g ...

  2. 『Numpy学习指南』排序&索引&抽取函数介绍

    排序: numpy.lexsort(): numpy.lexsort()是个排字典序函数,因为很有意思,感觉也蛮有用的,所以单独列出来讲一下: 强调一点,本函数只接受一个参数! import nump ...

  3. vs2015下通过opencv使用hdf5

    因为使用Kinect SDK编程,又需求高速文件I/O,所以通过opencv接口使用hdf5. (opencv 3.1以上版本,在其Extra Modules中支持hdf5) 一. 环境 OS: Wi ...

  4. CoderForce 148D-Bag of mice (概率DP求概率)

    题目大意:美女与野兽在玩画鸽子的游戏.鸽子在用黑布遮住的笼子里,白色的有w只,黑色的有b只,每次拿出一只作画,谁先画到白色的鸽子谁就赢.美女首先画,因为野兽太丑,它每次画的时候都会吓跑一只鸽子,所有出 ...

  5. 4. Median of Two Sorted Arrays *HARD* -- 查找两个排序数组的中位数(寻找两个排序数组中第k大的数)

    There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two ...

  6. Oracle12c中多宿主环境(CDB&amp;PDB)的数据库触发器(Database Trigger)

    Oracle12c中可插拔数据库(PDBs)上的多宿主数据库触发器 随着多宿主选项的引入,数据库事件触发器可以在CDB和PDB范围内创建. 1.   触发器范围 为了在CDB中创建数据库事件触发器,需 ...

  7. consumer的DubboResponseTimeoutScanTimer线程

    考虑这样一种情况,由于网络延时,consumer先抛出超时异常,一段时间后又收到了已经超时的响应,dubbo是怎么处理的? 拆分为3步看: 1. consumer的DubboResponseTimeo ...

  8. vue 表单校验(二)

    vue 表单校验(二) vue element-ui表单校验 由于现在使用element-ui进行form表单校验,因而使用其自带的校验规则进行校验,发现有些并不是那么好校验,或者说是校验起来很繁琐, ...

  9. mybatis标签之——<trim>

    trim标记是一个格式化的标记,主要用于拼接sql的条件语句(前缀或后缀的添加或忽略),可以完成set或者是where标记的功能. trim属性主要有以下四个  prefix:前缀覆盖并增加其内容   ...

  10. PHP:第二章——PHP中的流程控制语句

    if语句的集中形式 <?php /*if(条件) 语句; if(条件){语句块} if(条件){语句或语句块}else{语句或语句块} if(条件){语句或语句块}elseif(条件){语句或语 ...