标题:李白打酒


标题:李白打酒

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

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

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

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

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

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

 1 #include <iostream> 
 2 #include <cstring>
 3 using namespace std;
 4 int ans=0;
 5 
 6 void dfs(int alco,int store,int flower)
 7 {
 8     if(store==0&&flower==0)
 9     {
10         if(alco==1)
11             ans++;
12         return ;
13     }
14     if(store>0)
15     {
16         if(alco>0)
17             dfs(alco*2,store-1,flower);
18     }
19     if(flower)
20     {
21         if(alco>=0)
22             dfs(alco-1,store,flower-1);
23     }
24     return ;
25 }
26 
27 int main()
28 {
29     dfs(2,5,9);
30     cout<<ans<<endl;
31     return 0;
32 }
原文地址:https://www.cnblogs.com/767355675hutaishi/p/4296094.html