Codeforces Round #340-B. Chocolate-水+坑

http://codeforces.com/contest/617/problem/B


 给你 n个字符,01串

让你在2个相邻字符间加一分隔符 ,要求 分隔后的每一段至少包含一个 1

求分隔方案数

直接数1之间多少个0即可。。。

答案就是 (x1+1)*(x2+1)*(x3+1).....

注意题目坑点。。如果输入全0串。要输出0...............



#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <iostream>
using namespace std;   
double eps=0.000001; 

__int64 tm[105];
int main()
{

	__int64 st,i,j,k;
//	for (i=1;i<=50;i++)
//		printf("%d %d ",1,0);
	__int64 n;
	scanf("%I64d",&n);
	__int64 line=0;
	__int64 ans=1;
	int zero=0;
	for (i=1;i<=n;i++)
	{
		scanf("%I64d",&tm[i]);  
		if (tm[i]==1) zero=1;
	}
	
	for (i=1;i<=n;i++)
	{
		if (tm[i]==1){line=i+1;break;}
	}
	__int64 flag=0;
	if (line>n) flag=1;
	while(!flag)
	{
		__int64 tmp=1;
		for (i=line;i<=n;i++)
		{
			if(i==n) flag=1;
			if (tm[i]==0)
			{tmp++;}
			else
			{line=i+1;break;}
		} 
		if ((!flag)||(flag&&tm[n]==1))
		ans*=tmp;
	}
	if (zero==0) 
		printf("0\n");
	else
	printf("%I64d\n",ans);
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值