1) A stream is small in size, and frogs can jump from the left bank to the right bank. There is a stone pillar L on the left bank, and the stone pillar L area can only accommodate one frog. Similarly, there is also a stone pillar R on the right bank, and the stone pillar R area can only accommodate one frog.
2) there is a team of frogs numbered from small to big: 1. , n .
3) at first: frogs can only lie on the stone L on the left bank, one by number, and the small one falls on the big one-the big one is not allowed on the small one.
4) there are S pillars and y lotus leaves in the stream.
5) it is stipulated that if there are more than one frog on each pillar in the stream, only one frog is allowed to land on each lotus leaf.
6) for the stone pillar R on the right bank, like the stone pillar L on the left bank, multiple frogs are allowed to land, but one must fall one at a time, with the small one at the top and the big one at the bottom. (br > 7) Frogs are not allowed to jump back after jumping away from L on the left bank; similarly, frogs that jump from L on the left bank to R on the right bank, or from lotus leaves or stone pillars in the stream to R on the right bank are no longer allowed to leave.
question: how many frogs can be skipped if there are s stone pillars and y lotus leaves in the stream?
using namespace std;
int cross_river (int S, int y)
{
if(0 == S)
return y + 1;
else
return 2 * cross_river(S-1, y);
}
int main ()
{
int S, y;
cout << "Please input the number of and leaves:" << endl;
cin >> S >> y;
cout << "Number of frogs: " << cross_river(S, y) << endl;
system("pause");
return 0;
}
< hr > all the answers I found are shown above, which is a recursive question. But when the number of stone pillars is 3 or more, it will become the Tower of Hanoi, and it will be possible to jump innumerably to the other side.
0 lotus leaves, 3 stone pillars are not more than 8? Do I understand what"s wrong with the question? "