zoukankan      html  css  js  c++  java
  • SDUT 2623:The number of steps

    The number of steps

    Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^

    题目描述

        Mary stands in a strange maze, the maze looks like a triangle(the first layer have one room,the second layer have two rooms,the third layer have three rooms …). Now she stands at the top point(the first layer), and the KEY of this maze is in the lowest layer’s leftmost room. Known that each room can only access to its left room and lower left and lower right rooms .If a room doesn’t have its left room, the probability of going to the lower left room and lower right room are a and b (a + b = 1 ). If a room only has it’s left room, the probability of going to the room is 1. If a room has its lower left, lower right rooms and its left room, the probability of going to each room are c, d, e (c + d + e = 1). Now , Mary wants to know how many steps she needs to reach the KEY. Dear friend, can you tell Mary the expected number of steps required to reach the KEY?


    输入

    There are no more than 70 test cases. 
     
    In each case , first Input a positive integer n(0
    The input is terminated with 0. This test case is not to be processed.

    输出

    Please calculate the expected number of steps required to reach the KEY room, there are 2 digits after the decimal point.

    示例输入

    3
    0.3 0.7
    0.1 0.3 0.6
    0 

    示例输出

    3.41

    迷失在幽谷中的鸟儿,独自飞翔在这偌大的天地间,却不知自己该飞往何方…

    #include <iostream>
    #include <string.h>
    #include <stdio.h>
    using namespace std;
    double dp[100][100];
    int n;
    double a,b,c,d,e;
    int main()
    {
        while(cin>>n&&n)
        {
            cin>>a>>b>>c>>d>>e;
            memset(dp,0,sizeof(dp));
            for(int i=2; i<=n; i++)
                dp[n][i]+=dp[n][i-1]+1;//处理最后一行
            for(int i=n-1; i>=1; i--) //从倒数第二行开始处理
            {
                dp[i][1]+=a*(dp[i+1][1]+1)+b*(dp[i+1][2]+1);//处理每一行的第一列
                for(int j=2; j<=n; j++)
                    dp[i][j]+=c*(dp[i+1][j]+1)+d*(dp[i+1][j+1]+1)+e*(dp[i][j-1]+1);//处理每一行的除了第一列以外的其它列
            }
            printf("%.2lf
    ",dp[1][1]);
        }
        return 0;
    }


  • 相关阅读:
    #ACsaber ——简单排序、字符串加空格、数组中的行 ~20.10.22
    #堆排序 20.09.27
    #并查集 20.09.25
    #卡特兰数 #抽屉原理 #Nim游戏 ——杂记
    #扩展欧几里得算法 ——线性同余方程 ~20.9.4
    #周测 7 —— 数的划分 、逆序对 、排座椅 、棋盘
    117. 占卜DIY
    116. 飞行员兄弟
    115.给树染色
    112.雷达设备
  • 原文地址:https://www.cnblogs.com/im0qianqian/p/5989374.html
Copyright © 2011-2022 走看看