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