期望DP

期望DP的一般做法是从末状态開始递推:

Problem Description
Akemi Homura is a Mahou Shoujo (Puella Magi/Magical Girl).

Homura wants to help her friend Madoka save the world. But because of the plot of the Boss Incubator, she is trapped in a labyrinth called LOOPS.

The planform of the LOOPS is a rectangle of R*C grids. There is a portal in each grid except the exit grid. It costs Homura 2 magic power to use a portal once. The portal in a grid G(r, c) will send Homura to the grid below G (grid(r+1, c)), the grid on the right of G (grid(r, c+1)), or even G itself at respective probability (How evil the Boss Incubator is)!
At the beginning Homura is in the top left corner of the LOOPS ((1, 1)), and the exit of the labyrinth is in the bottom right corner ((R, C)). Given the probability of transmissions of each portal, your task is help poor Homura calculate the EXPECT magic power she need to escape from the LOOPS.





Input
The first line contains two integers R and C (2 <= R, C <= 1000).

The following R lines, each contains C*3 real numbers, at 2 decimal places. Every three numbers make a group. The first, second and third number of the cth group of line r represent the probability of transportation to grid (r, c), grid (r, c+1), grid (r+1, c) of the portal in grid (r, c) respectively. Two groups of numbers are separated by 4 spaces.

It is ensured that the sum of three numbers in each group is 1, and the second numbers of the rightmost groups are 0 (as there are no grids on the right of them) while the third numbers of the downmost groups are 0 (as there are no grids below them).

You may ignore the last three numbers of the input data. They are printed just for looking neat.

The answer is ensured no greater than 1000000.

Terminal at EOF



Output
A real number at 3 decimal places (round to), representing the expect magic power Homura need to escape from the LOOPS.


Sample Input
2 2 0.00 0.50 0.50 0.50 0.00 0.50 0.50 0.50 0.00 1.00 0.00 0.00

Sample Output
6.000

dp[i][j]表示点(i,j)到达(r,c)的期望步数:

特殊处理呆在原地概率为1的点。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<limits.h>
typedef long long LL;
using namespace std;
const int maxn=1000+100;
double dp[maxn][maxn];
double p[maxn][maxn][3];
int r,c;int main()
{while(~scanf("%d%d",&r,&c)){for(int i=1;i<=r;i++){for(int j=1;j<=c;j++)scanf("%lf%lf%lf",&p[i][j][0],&p[i][j][1],&p[i][j][2]);}memset(dp,0,sizeof(dp));for(int i=r;i>=1;i--){for(int j=c;j>=1;j--){if(p[i][j][0]==1)  continue;else  dp[i][j]=(dp[i][j+1]*p[i][j][1]+dp[i+1][j]*p[i][j][2]+2)/(1-p[i][j][0]);}}printf("%.3f\n",dp[1][1]);}return 0;
}


 
 UPC  2225: The number of steps 

Description

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?

 

Input

There are no more than 70 test cases. 
In each case , first Input a positive integer n(0<n<45), which means the layer of the maze, then Input five real number a, b, c, d, e. (0<=a,b,c,d,e<=1, a+b=1, c+d+e=1). 
The input is terminated with 0. This test case is not to be processed.

Output

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

Sample Input

30.3 0.70.1 0.3 0.60 

Sample Output

3.41
#include<iostream> 
#include<cstdio> 
#include<cstring> 
#include<algorithm> 
#include<limits.h> 
typedef long long LL; 
using namespace std; 
double a,b,c,d,e; 
double dp[50][50]; 
int main() 
{ int n; while(~scanf("%d",&n)&&n) { scanf("%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e); for(int i=1;i<=n;i++) dp[n][i]=i-1; for(int i=n-1;i>=1;i--) { dp[i][1]=dp[i+1][1]*a+dp[i+1][2]*b+1; for(int j=2;j<=i;j++) dp[i][j]=dp[i+1][j]*c+dp[i+1][j+1]*d+dp[i][j-1]*e+1; } printf("%.2f\n",dp[1][1]); } return 0; 
} 
POJ 2096

Description

Ivan is fond of collecting. Unlike other people who collect post stamps, coins or other material stuff, he collects software bugs. When Ivan gets a new program, he classifies all possible bugs into n categories. Each day he discovers exactly one bug in the program and adds information about it and its category into a spreadsheet. When he finds bugs in all bug categories, he calls the program disgusting, publishes this spreadsheet on his home page, and forgets completely about the program. 
Two companies, Macrosoft and Microhard are in tight competition. Microhard wants to decrease sales of one Macrosoft program. They hire Ivan to prove that the program in question is disgusting. However, Ivan has a complicated problem. This new program has s subcomponents, and finding bugs of all types in each subcomponent would take too long before the target could be reached. So Ivan and Microhard agreed to use a simpler criteria --- Ivan should find at least one bug in each subsystem and at least one bug of each category. 
Macrosoft knows about these plans and it wants to estimate the time that is required for Ivan to call its program disgusting. It's important because the company releases a new version soon, so it can correct its plans and release it quicker. Nobody would be interested in Ivan's opinion about the reliability of the obsolete version. 
A bug found in the program can be of any category with equal probability. Similarly, the bug can be found in any given subsystem with equal probability. Any particular bug cannot belong to two different categories or happen simultaneously in two different subsystems. The number of bugs in the program is almost infinite, so the probability of finding a new bug of some category in some subsystem does not reduce after finding any number of bugs of that category in that subsystem. 
Find an average time (in days of Ivan's work) required to name the program disgusting.

Input

Input file contains two integer numbers, n and s (0 < n, s <= 1 000).

Output

Output the expectation of the Ivan's working days needed to call the program disgusting, accurate to 4 digits after the decimal point.

Sample Input

1 2

Sample Output

3.0000
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<limits.h>
typedef long long LL;
using namespace std;
double dp[1100][1000];
double n,s;int main()
{while(~scanf("%lf%lf",&n,&s)){dp[(int)n][(int)s]=0.0;for(int i=n;i>=0;i--){for(int j=s;j>=0;j--){if(i==n&&j==s)   continue;dp[i][j] = ( n*s + (n-i)*j*dp[i+1][j] + i*(s-j)*dp[i][j+1] + (n-i)*(s-j)*dp[i+1][j+1] )/( n*s - i*j );}}printf("%.4lf\n",dp[0][0]);}return 0;
}


 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/290418.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

神奇的[Caller*]属性

前言上次&#xff0c;我们《使用 CallerArgumentExpression 检查弃元参数》&#xff0c;它实际是利用编译器编译时将变量名称传入。其实&#xff0c;.NET中提供了多个[Caller*]属性&#xff0c;帮助我们轻松获取调用者信息。CallerFilePathAttribute允许获取包含调用方的源文件…

java dateTime + long

2019独角兽企业重金招聘Python工程师标准>>> public static void main(String[] args) throws Exception{SimpleDateFormat sdfnew SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // long timeStartsdf.parse("2011-09-20 12:30:45").getTime();l…

.NET Core中异常过滤器ExceptionFilter的使用介绍

介绍实现需要继承IExceptionFilter 或 IAsyncExceptionFilter。可用于实现常见的错误处理策略。使用场景首先讲一下我们为什么要使用异常过滤器 &#xff0c;如果业务场景复杂&#xff0c;只使用HttpStatusCode&#xff0c;抛出异常后,后期要加很多字段来描述。那么这种就比较不…

程序一启动检查网络,如果没有网络就退出程序

转载于:https://www.cnblogs.com/songxing10000/p/4823812.html

看小说的这些年

从大一开始&#xff0c;就开始看起了小说&#xff0c;不是那种名著类型&#xff0c;而是快餐小说&#xff0c;玄幻、都市、言情、科幻&#xff0c;什么都会看&#xff0c;因为看多了&#xff0c;就会发现&#xff0c;已经没什么可以看的。 谈起快餐小说&#xff0c;已经有很多被…

COMA(一): Learning to Communicate with Deep Multi-Agent Reinforcement Learning 论文讲解

Learning to Communicate with Deep Multi-Agent Reinforcement Learning 论文讲解 论文链接&#xff1a;https://papers.nips.cc/paper/6042-learning-to-communicate-with-deep-multi-agent-reinforcement-learning.pdf &#xff08;这篇论文是COMA三部曲中的第&#xff08…

C和指针之指针数组和指向数组的指针

1、指针数组 定义一个指针数组&#xff0c;该数组中每个元素是一个指针&#xff0c;每个指针指向哪里就需要程序中后续再定义int *p[10]; 2、指向数组的指针 定义一个数组指针&#xff0c;该指针指向含10个元素的一维数组&#xff08;数组中每个元素是int型&#xff09;int (*p…

SSH 远程执行任务

SSH 是 Linux 下进行远程连接的基本工具&#xff0c;但是如果仅仅用它来登录那可是太浪费啦&#xff01;SSH 命令可是完成远程操作的神器啊&#xff0c;借助它我们可以把很多的远程操作自动化掉&#xff01;下面就对 SSH 的远程操作功能进行一个小小的总结。远程执行命令如果我…

分库分表之历史表如何选择最佳分片路由规则

前言先别急着关闭,我相信这篇文章应该是所有讲分表分库下的人都没有和你们讲过的一种分片模式,外面的文章基本上都是教你如何从零开始分片,现在我将讲解的是如何从1开始分片项目地址github地址 https://github.com/dotnetcore/sharding-coregitee地址 https://gitee.com/dotnet…

COMA(二):Counterfactual Multi-Agent Policy Gradients 论文讲解

Counterfactual Multi-Agent Policy Gradients 论文链接&#xff1a;https://arxiv.org/pdf/1705.08926.pdf 1. 问题提出&#xff08;解决了什么问题&#xff1f;&#xff09; 在现实世界中&#xff0c;有非常多的问题需要多个单位之间的“合作”才能完成任务&#xff0c;这就…

lecture6-mini批量梯度训练及三个加速的方法

Hinton的第6课&#xff0c;这一课中最后的那个rmsprop&#xff0c;关于它的资料&#xff0c;相对较少&#xff0c;差不多除了Hinton提出&#xff0c;没论文的样子&#xff0c;各位大大可以在这上面研究研究啊。 一、mini-批量梯度下降概述 这部分将介绍使用随机梯度下降学习来训…

Dapr集成之GRPC 接口

Dapr 为本地调用实现 HTTP 和 gRPC API 。通常大家第一时间想到的是通过 gRPC 调用 Dapr&#xff0c;更重要的一点是Dapr 也可以通过 gRPC 与应用程序通信。要做到这一点&#xff0c;原理很简单&#xff0c;应用程序需要托管一个gRPC服务器&#xff0c;并实现 Dapr 的GRPC 规范…

jQuery Validate验证框架详解

jQuery Validate验证框架详解 jQuery校验官网地址&#xff1a;http://bassistance.de/jquery-plugins/jquery-plugin-validation 一、导入js库 <script type"text/javascript" src"<%path %>/validate/jquery-1.6.2.min.js"></script> &…

RNN入门笔记

本笔记来源自Youtube李宏毅老师的RNN视频归纳&#xff0c;主要分为以下几个知识点: RNN 的特点RNN 的几种实现方法 (Simple RNN, LSTM)RNN 的训练不稳定性RNN 的keras实现 (定长和变长输入案例) Recurrent Neural Network Feature of RNN Differ from normal Neural Networ…

WPF 基础控件之 DatePicker 样式

此群已满340500857 &#xff0c;请加新群458041663由于微信群人数太多入群请添加小编微信号yanjinhuawechat 或 W_Feng_aiQ 邀请入群需备注WPF开发者 PS&#xff1a;有更好的方式欢迎推荐。支持NugetInstall-Package WPFDevelopers.Minimal -Version 3.2.001—代码如下一、创建…

stagefright框架(四)-Video Buffer传输流程

這篇文章將介紹Stagefright中是如何和OMX video decoder传送buffer。 (1) OMXCodec會在一開始的時候透過read函式來傳送未解碼的data給decoder&#xff0c;並且要求decoder將解碼後的data傳回來 status_t OMXCodec::read(...){ if (mInitialBufferSubmit) { mInitialBuffe…

微信支付四大支付模式分别有哪些区别?

微信支付是集成在微信客户端的支付功能&#xff0c;用户可以通过手机完成快速的支付流程。微信支付已为百货、餐厅、便利店、酒店、快递、景区、医院、售货机等提供了支付与营销的全方位支持。 目前微信支付已实现刷卡支付、扫码支付、公众号支付、APP支付&#xff0c;并提供企…

利用Deep Reinforcement Learning训练王者荣耀超强AI

Mastering Complex Control in MOBA Games with Deep Reinforcement Learning&#xff08;一&#xff09;知识背景&#xff08;二&#xff09;系统架构&#xff08;三&#xff09;算法结构3.1 Target Attention3.2 利用LSTM学习技能连招释放3.3 Decoupling of Control Dependen…

C和指针之编译出现warning: implicit declaration of function ‘matrix_multiply‘ is invalid in C99问题

1、问题 在我的mac上编译一个c文件&#xff0c;出现下面错误2、原因和解决办法 是因为我用vim的时候&#xff0c;把函数名少写了一个字符导致&#xff0c;把这个函数名改正就行了。

5. 堪比JMeter的.Net压测工具 - Crank 实战篇 - 接口以及场景压测

1. 前言通过之前的学习&#xff0c;我们已经掌握了crank的配置以及对应http基准工具bombardier、wrk、wrk2的用法&#xff0c;本篇文章介绍一下如何将其用于实战&#xff0c;在实际的项目中我们如何使用crank来完成压测任务。2. 项目背景目前有一个项目&#xff0c;我们希望通过…