zoukankan      html  css  js  c++  java
  • Codeforces Round #340 (Div. 2) B. Chocolate 水题

    B. Chocolate

    题目连接:

    http://www.codeforces.com/contest/617/problem/D

    Descriptionww.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

    5
    1 0 1 0 1

    Sample Output

    4

    Hint

    题意

    给你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;
    }
  • 相关阅读:
    JVM启动参数小结
    Java 线程池学习
    myeclipse 8.5安装freemarker插件方法
    开源文件比较工具:WinMerge、KDiff3、diffuse
    初探淘宝技术构架
    Java获取IP地址:request.getRemoteAddr()注意
    Spring MVC 教程,快速入门,深入分析
    分布式服务框架 Zookeeper -- 管理分布式环境中的数据
    YARN作业提交流程剖析
    经典的MapReduce1解析
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5156313.html
Copyright © 2011-2022 走看看