Li Bai drinking-blue bridge cup, Li Bai Drinking blue bridge

Source: Internet
Author: User

Li Bai drinking-blue bridge cup, Li Bai Drinking blue bridge

Li Bai's drinking problems

"Li Bai walked down the street and raised his pot to buy wine. When the shop doubled, he saw flowers and drinks." On the way, he met the shop five times and saw 10 of the flowers. There were two drinks in the pot, in the end, I just need to finish drinking. The last thing I want to meet is flowers. What are the possible situations?

Analysis: the question is to meet the flowers, that is to say, to drink (it is better to just finish the wine). This is a definite situation, and the rest is: there is a fight of wine, I met five stores and nine Flowers (I made five drinks and drank nine drinks ).

Then, there are only two types of scenarios: Meeting flowers and drinking wine and meeting shops.

// Dfs (num-1, mum, s * 2) + dfs (num, mum-1, s-1 );

When you encounter a store, you need to shoot (s * 2). Then, the number of liquor fights doubles. When you encounter flowers, you need to drink alcohol, and then the number of liquor fights is reduced by 1 (S-1 );

Then set the recursive Exit:

When the wine is still spent, return 0; think that the wine cannot be negative;

Return 0 if all five stores are outdated;

Return 0 if all nine flowers have expired;

When the flowers are just met, the store is just met, and there is a fight for wine: return 1;

In the middle of the process, when the wine is over, but the shop is met, and because s = 0 at this time, when the shop is hit (s * 2), we need to set s to 0.5;

/*********** For personal understanding. Welcome to the discussion *************/

  

 1 #include<stdio.h> 2 int dfs(int num,int mum,int s){ 3     if(s<0 || num<0 || mum<0) 4     return 0; 5     if(num<0 || mum<0) 6     return 0; 7     if(num==0 && mum==0&& s==1) 8     return 1; 9     if(s==0 && num>0 && mum>=0)10     s=0.5;11     return dfs(num-1,mum,s*2)+dfs(num,mum-1,s-1);12 }13 int main()14 {15     printf("%d",dfs(5,9,2));16     return 0;17  } 

 

    

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.