Searches related to Suppose I have a red block (R) of height 1, a blue block (B) of height 2, and a green block (G) of height 3. I can stack the blocks one above the other to build a tower. For example, I can stack in the order RGB and I would get a tower of height 6. I wish to compute how many different towers of a given height n can be built if there are ample blocks of each colour. Let Tn) denote the number of towers of height n. Write a c++ program that prints T(n) given n.
Answers
Answered by
2
Answer:
long int T(int n)
{
if(n<0)
return 0;
else if(n==1)
return 1;
else if(n==2)
return 2;
else if(n==3)
return 4;
else
return T(n-1)+T(n-2)+T(n-3);
}
main_program{
int num;
cin>>num;
cout<<T(num)<<endl;
}
Explanation:This program helps to count and print the number of combinations possible with respect to he given value of n.
Similar questions