SDUT 2623:The number of steps

369人阅读 评论(0) 收藏 举报
分类:

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\n",dp[1][1]);
    }
    return 0;
}


查看评论

sdut 2623 The number of steps (概率dp)

题意: 一个金子塔型的迷宫,一个人在金子塔的定点,现在要走到金子塔的左下角,给出了这个人走左边的们,左下角的们,右下角的门,对应的概率,现在问这个人走到金子塔左下角步数的期望。 题解: 直接搞,...
  • My_ACM_Dream
  • My_ACM_Dream
  • 2015-04-07 16:26:20
  • 310

codeforces Minimum number of steps 思维

D. Minimum number of steps time limit per test1 second memory limit per test256 megabytes inputst...
  • Littlewhite520
  • Littlewhite520
  • 2017-05-05 21:33:41
  • 438

hdu1391Number Steps

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1391 x,y的范围是 0到5000.。。。 代码: #include struct p...
  • wsn564533648
  • wsn564533648
  • 2016-05-04 21:38:06
  • 189

Codeforces805D. Minimum number of steps

D. Minimum number of steps time limit per test 1 second memory limit per test 256 megabytes in...
  • Jelly_acm
  • Jelly_acm
  • 2017-05-05 08:46:52
  • 478

2014北大软工夏令营机试 B:Number Steps

#include using namespace std; int Query(int a,int b){ int m=0,n=0,sum=0; while(true){ ...
  • moweiyang0214
  • moweiyang0214
  • 2014-07-19 23:36:26
  • 585

sdut 3257 Cube Number

求乘积为立方数的数对个数。(不考虑数对中数的相对顺序) 先筛掉每个原数中的立方因子得到新数,对于每一个新数,若存在平方因子,则需要找该平方因子为1的对应的数与其匹配;若不存在平方因子(即只含单个因...
  • u014679804
  • u014679804
  • 2015-07-25 11:48:56
  • 477

ZOJ 1414:Number Steps

Number Steps Time Limit: 2 Seconds      Memory Limit: 65536 KB Starting from point (0,0) on a ...
  • qq_28954601
  • qq_28954601
  • 2016-02-01 20:51:27
  • 246

SDUT 3258 Square Number(2015年山东省第六届ACM大学生程序设计竞赛)

Square Number Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 In mathematics, a ...
  • llwwlql
  • llwwlql
  • 2016-06-02 14:29:45
  • 1183

sdut 3258 Square Number 打表

Square Number Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 In mat...
  • zp___waj
  • zp___waj
  • 2016-05-20 15:21:32
  • 472

第四届 The number of steps

Description Mary stands in a strange maze, the maze looks like a triangle(the first layer have on...
  • Misdom_Tian_Ya
  • Misdom_Tian_Ya
  • 2015-05-05 18:38:34
  • 298
    个人资料
    专栏达人 持之以恒
    等级:
    访问量: 37万+
    积分: 1万+
    排名: 1717
    寻找 Qianqian 遇见 就是幸运
    博客专栏
    最新评论