2014 The fifth session of the Blue Bridge Cup test-C + + program Design Group B--Li Bai Cider

Source: Internet
Author: User

Title Description:

Title: Li Bai Cider

Say the great poet Li Bai, a good drink in life. Fortunately, he never drives.

One day, he was carrying a flask, out of the house, a flask of wine 2. He sang while walking:

Walk in the street, lift the pot to cider.
Every shop adds one times, meets the flower to drink a fight.

On this road, he met the shop 5 times, met the flowers 10 times, known the last encounter is a flower, he just drank the wine.

Please calculate the order that Li Bai meets the shop and the flower, can take the shop to remember as a, meet the flower to remember as B. Then: BABAABBABBABBBB is a reasonable order. How many are there in the answer like this? Please calculate the number of all possible scenarios (including the topic given).

Note: Submit an answer via the browser. The answer is an integer. Don't write any extra content.

Problem Solving Ideas:

Global variables: Number of scenarios, array of order

Three local variables: wine, shop, flower

Using cyclic recursion

Program code:

int count = 0;
Char a[15];

void Fun (int i,int store, int flower, int wine) {
function End Condition
if ((store>5) | | | (FLOWER>10)) Return
else if ((store==5) && (flower==10) && (i==15)) {
if (a[14]== ' B ' &&wine==0) {
count++;
}
Return
}

Add one more times to every shop
A[i]= ' a ';
Fun (i+1,store+1,flower,wine*2);

Meet the flowers and lose a fight
A[i]= ' B ';
Fun (i+1,store,flower+1,wine-1);

}
int main (int argc, char *argv[]) {

Fun (0,0,0,2);

printf ("%d", count);
return 0;
}

Answer: 14

2014 The fifth session of the Blue Bridge Cup test-C + + program Design Group B--Li Bai Cider

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.