Expected number of bnu34978 bnu34978 for BNU 34978 Tower

Source: Internet
Author: User

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;}





Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.