zoukankan      html  css  js  c++  java
  • 第五届蓝桥杯c/c++B组3

    题目三:李白打酒


    标题:李白打酒

        话说大诗人李白,一生好饮。幸好他从不开车。

        一天,他提着酒壶,从家里出来,酒壶中有酒2斗。他边走边唱:

        无事街上走,提壶去打酒。
        逢店加一倍,遇花喝一斗。

        这一路上,他一共遇到店5次,遇到花10次,已知最后一次遇到的是花,他正好把酒喝光了。

        请你计算李白遇到店和花的次序,可以把遇店记为a,遇花记为b。则:babaabbabbabbbb 就是合理的次序。像这样的答案一共有多少呢?请你计算出所有可能方案的个数(包含题目给出的)。

        注意:通过浏览器提交答案。答案是个整数。不要书写任何多余的内容。

    #include<iostream>
    #include<cmath>
    using namespace std;
    int main() {
      int arr[16], x, y, s=0, v;
      for (arr[0]=0; arr[0]<=1; arr[0]++)
       for (arr[1]=0; arr[1]<=1; arr[1]++)
        for (arr[2]=0; arr[2]<=1; arr[2]++)
         for (arr[3]=0; arr[3]<=1; arr[3]++)
          for (arr[4]=0; arr[4]<=1; arr[4]++)
           for (arr[5]=0; arr[5]<=1; arr[5]++)
            for (arr[6]=0; arr[6]<=1; arr[6]++)
             for (arr[7]=0; arr[7]<=1; arr[7]++)
              for (arr[8]=0; arr[8]<=1; arr[8]++)
               for (arr[9]=0; arr[9]<=1; arr[9]++)
                for (arr[10]=0; arr[10]<=1; arr[10]++) 
                 for (arr[11]=0; arr[11]<=1; arr[11]++)
                  for (arr[12]=0; arr[12]<=1; arr[12]++)
                   for (arr[13]=0; arr[13]<=1; arr[13]++){
                     v=2, x=0, y=0;
                     for (int i=0; i<14; i++){
                       if (arr[i]==0){
                          x++;
                          v=v+v;
                          //cout<<x<<endl;
                       }
                       if (arr[i]==1){
                         y++;
                         v-=1;
                         //cout<<v<<endl;
                       }
                       if (x==5&&y==9&&v==1)
                       s++;   
                     }
                   }
      cout<<s;
    }
    #include<iostream>
    using namespace std;
    int arr[20], s=0;;
    void dfs(int a, int b, int x, int y){
      if (b==15){
        if (x==5&&y==9&&a==1){
          s++;
          for (int i=0; i<15; i++)
            cout<<arr[i]<<" "; 
          cout<<endl;
        }
      }
      else{
        arr[b]=1;
        dfs(a*2, b+1, x+1, y);
        arr[b]=0;
        dfs(a-1, b+1, x, y+1);
      }
    }
    int main() {
      dfs(2, 1, 0, 0);
      cout<<s;
    }
    

      

  • 相关阅读:
    C#SortedList排序列表怎么样逆序输出
    使 SortList 实现重复键排序
    【转】delphi程序只允许运行一个实例的三种方法:
    Delphi中控制Excel(转载)
    spring和hibernate的集成
    使用Jedis操作redis
    使用java发送邮件
    error at ::0 can't find referenced pointcut...解决方法
    log4j简单的使用
    spring学习笔记三:Component注解(把POJO类实例化到spring的IOC容器中)
  • 原文地址:https://www.cnblogs.com/a863886199/p/6573142.html
Copyright © 2011-2022 走看看