Expected number of bnu34978 bnu34978 for BNU 34978 Tower
Question link: Click the open link
When we use dp [I] to represent random I plates, we can restore the expected number of steps required in the original position.
F [I] indicates the number of steps for playing the ordinary tower on my plate.
Since it is random, we think it is the last random case,
Place the nth column at the bottom of any column.
If 3rd columns are randomly placed, the number of steps is dp [n-1].
If you move the first n-1 plates to the first 1st columns, the cost is dp n-1].
Then, move n to the third pillar, and move the other plates to the third pillar. The cost is 1 + f [n-1].
Is like this _ (: zookeeper success )_
#include <cstdio>#include <iostream>#include <algorithm>#include <string.h>#include <vector>#include <cmath>using namespace std;#define N 100#define ll long longll n;double f[N];double dp[N];int main() { f[1] = 1.0; for(int i = 2; i < N; i++) f[i] = f[i-1]*2.0+1.0; dp[1] = 0.666666666666666; for(int i = 2; i < N; i++) dp[i] = dp[i-1]/3.0 + 2.0 * (dp[i-1] + f[i-1] +1.0) / 3.0; int T, j;scanf("%d",&T); while(T--) { scanf("%d",&j); printf("%.2f\n", dp[j]); } return 0;}