When the frog crossed the river, I got it wrong. Recursive Hanoi Tower

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?

< hr > < H1 > include < iostream > < / H1 >

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? "

Apr.28,2021

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 frogs that jump from lotus leaves or stone pillars in the stream to R on the right bank are no longer allowed to leave.
it is this condition that can not be completely equated with the Tower of Hanoi


the difference between the Tower of Hanoi and this question is that the ultimate goal of this question is to enter only once, while the Tower of Hanoi can go back and forth. If the R pillar cannot come down once it goes up, if there is no column, there are only lotus leaves, then the number of R posts can be equal to the number of lotus leaves + 1, which is easy to understand. If you add another bead, then the number will be doubled. And so on.


who can tell me how many frogs can jump over 0 lotus leaves and 3 stone pillars? All the answers I found were eight.
this is a recursive problem. I want to know the answer to this question. "my answer is innumerable. I can't count it. no, no, no.


0 lotus leaf, n pillars think of it this way, suppose there are n pillars in the river:

    When
  • n = 0, at most one frog jumps directly to the R column. There is no need to explain this
  • When
  • n = 1, because there is an extra place in the river, this column (A column) can first jump down from L column to one more frog, and then this A column and L column can jump up to 2 frogs to R column
  • .
  • when n = 2, because there is another column (B column) in the river, you can first jump from L column to B column, then the frog of A column can also jump to B column, then there are two frogs on B column, then L column jumps one frog to A column, and then you can't jump any more frogs. Finally, L column jumps one frog to R column, A pillar jumps 1 frog. There are 2 B-pillar jumps (here you need to jump to A-pillar after A-pillar, and then jump R-pillar), a total of 4
  • When
  • n = 3, we can basically see the law of recursion. For example, in the case above, if there is an extra C column, then this column can first jump a frog down from the L column, and then all the frogs on the other pillars in the river jump to the C column. The frog on the C column is equal to 1 (A pillar frog) + 2 (B pillar frog) + 1 (L pillar newly jumped frog) = 4, and then the B column is 2 according to the previous situation. A column is 1, and at most 1 + 2 + 4 + 1 = 8
  • When
  • n = 4, according to the above rule, we can know that one frog jumps from the L column on the D column, then the frogs of the other columns jump over, a total of 8 frogs, and then jump at most 1 + 2 + 4 + 8 + 1 = 16
  • .
  • . (abbreviated)

this process seems to be very similar to the Tower of Hanoi, but not the Tower of Hanoi.

finally, on this basis, consider the case that the lotus leaf is not zero, because only one frog can jump on the lotus leaf, which is equivalent to magnifying the scale of the problem. so the final answer is the number of lotus leaves + 1 (the frog that jumps directly to the R column) and multiply it by 2 according to the number of columns in the river.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e99771-175a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e99771-175a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?