[HDU] 3853 LOOPS 期望dp入门

VFIO框架源码分析(二十二)- IOMMUFD 的脏页跟踪与 Dirty Bits 读取 在虚拟化热迁移(Live Migration)的场景中,脏页追踪(Dirty Page Tracking)是最具挑战性的环节之一。它的核心任务是实时捕获设备(DMA)对内存的写操作,以便 VMM(如 QEMU)知道哪些内存页需要被重新传输到目标主机。在强耦合与粗粒度:脏页追踪是绑定在 Container 上的。这意味着,如果一个 Container 内有多个设备,哪怕只有一个设备在写内存,脏页追踪也会影响 Container 内的所有设备。软件模拟开销大。 阅读详情

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

就是说有一个R*C的矩阵, 求从1,1 走到R ,C 的期望消耗能量数, 移动一格算2个能量, 对于每个点, 会有不动, 向右走, 向下走的几率, 注意原地不动也要消耗能量. 仍然是普通期望dp, 直接从dp[R][C]倒推过来即可. 注意有原地不动的概率为1.00的情况, 要特判, 因为那个点永远无法走到.

dp方程由期望的线性性可得到:
dp[i][j]=p1[i][j]*dp[i][j]+p2[i][j]*dp[i][j+1]+p3[i][j]*dp[i+1][j]+2;
化简得到:
dp[i][j]=p2[i][j]*dp[i][j+1]/(1-p1[i][j])+p3[i][j]*dp[i+1][j]/(1-p1[i][j])+2/(1-p1[i][j]);
dp[i][j]表示在(i, j)到终点还需的期望步数.

#include<stdio.h>
#include<cmath>
const double eps = 1e-7;
const int maxn = 1010;
int R, C;
double dp[maxn][maxn], p1[maxn][maxn], p2[maxn][maxn], p3[maxn][maxn];
int main(){
    while(scanf("%d%d", &R, &C) != EOF){
        for(int i = 1; i <= R; ++i)
            for(int j = 1; j <= C; ++j) 
                scanf("%lf%lf%lf", &p1[i][j], &p2[i][j], &p3[i][j]);
        dp[R][C] = 0;
        for(int i = R; i; --i)
            for(int j = C; j; --j)
                if(i ^ R || j ^ C){
                    if(fabs(1 - p1[i][j]) < eps) continue;
                    dp[i][j] = (dp[i][j+1] * p2[i][j] + dp[i+1][j] * p3[i][j] + 2) / (1 - p1[i][j]);
                }
        printf("%.3lf\n", dp[1][1]);
    }
}
用LangFuse+LangChain打造可观测的AI应用:从埋点到成本监控实战 本文详细介绍了如何将开源可观测性平台LangFuse深度集成到基于LangChain构建的AI应用中,特别是电商客服机器人场景。通过从基础SDK集成、提示词管理到成本监控的完整实战,帮助开发者实现对LLM应用内部工作流的清晰追踪、问题排查与费用分析,从而打造稳定、可控的生产级AI应用。 阅读详情

相关推荐

Python+Vue计算机毕业设计风电场监控系统的设计与实现7bd6i(程序+LW+源码+部署)

Python3.7.7+Django+Mysql5.7+pip list+HBuilderX(Vscode也行)+Vue+Pychram社区版。2. 前端:vue+css+javascript+jQuery+easyUI+highcharts。2.IDE环境:Python和Python 社区版都可以。Django + Vue +Python+Mysql 等等组成,B/S模式等等。该项目含有源码、文档、程序、数据库、配套开发软件、软件安装教程。1. 后端:Python、Vue、Django、Mysql。

华信计算机毕设源码程序 349

【HDU3853】LOOPS 期望与概率

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...

Tmotfl的博客 368

保姆级教程:用Altium Designer 24从零画一块PCB(附完整库文件与避坑清单)

本文提供了一份详细的Altium Designer 24(AD24)PCB设计教程,从工程创建到最终文件输出,涵盖元件库管理、原理图设计、PCB布局布线等全流程。特别适合初学者,包含STM32最小系统板的实战案例,附完整库文件和避坑清单,帮助用户快速掌握AD24的核心功能与技巧。

weixin_27697385的博客 256

hdu 3853 LOOPS

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 LOOP

温文尔雅 243

Linux中Hadoop 集群搭建

零、下载Hadoop: http://archive.cloudera.com/cdh5/cdh/5/?tdsourcetag=s_pctim_aiomsg 一、集群规划: 搭建的 hadoop 集群由 3 台服务器组成,分别叫做 master,salve1 和 slave2。其中 master 作为主节点,slave1 和 slave2 作为从节点。 二、网络配置: 1.查看 3 个节点的主机名...

白墨的小白博客 3996

IAR for ARM 搭建STM32F103C8T6工程模板(实战指南)

本文详细介绍了如何在IAR for ARM开发环境中为STM32F103C8T6微控制器搭建完整的工程模板。从环境准备、固件库获取、目录结构设计到工程配置与编译调试,提供了实战指南和常见问题解决方案,帮助开发者快速建立稳定的STM32开发环境。

fun88的博客 994

HDU 3853 LOOPS(概率DP)

  LOOPS Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/Others)Total Submission(s): 649    Accepted Submission(s): 267 Problem Description Akemi Homura is a Mahou Sho...

weixin_34124577的博客 233

实测昇腾310P跑Qwen3有多慢?手把手带你部署vLLM并记录性能数据

本文实测了昇腾310P在vLLM框架下部署Qwen3模型的性能表现,详细记录了2.5 tokens/s的生成速度及其技术瓶颈。通过环境搭建、基准测试和深度分析,揭示了计算资源利用率不足等关键问题,并提供了实用的优化技巧与监控方案,帮助开发者更好地理解和优化昇腾平台上的大模型部署。

weixin_28724319的博客 906

文章标题 HDU 3853:LOOPS (概率DP)

LoopsDescriptionAkemi 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 laby

Wang_SF2015的博客 481

SAP 基于生产订单行项目外部加工创建采购申请时的一个增强需求

摘要 本文介绍在SAP系统中实现生产订单外协工序自动生成采购申请(PR)时,将指定文本写入PR抬头文本的技术方案。关键点包括: 业务背景:通过CO02事务码将工序标记为外部加工,系统自动生成PR,需在生成时自动写入抬头文本。 技术难点: PR抬头文本存储在STXH/STXL而非EBAN表 标准增强点ME_PROCESS_REQ_CUST在外协场景可能不触发 推荐方案: 使用BAdI ME_REQ_POSTED,在PR过账时点执行 通过Text Object EBANH和Text ID(如B01)写入文本 实

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 638

在ubuntu20.04中安装MATLAB时常见问题及解决方法

   如果你刚装完ubuntu20.04,这时你想要安装MATLAB2021A,在输入命令./install进行安装时,可能会报以下错误:    terminate called after throwing an instance of ‘JailContainerException’ what(): Error: 88: No JRE version parsed from/media/jzx/MATHWORKS_R2021A/sys /java/jre/glnxa64/jre/release   

慕羽★的博客 1万+

HDU 3853 LOOPS【期望DP】

DescriptionAkemi 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

Sdywolf的博客 472

31、Labview如何搭建程序框架?--状态机到数据采集等常用框架

本文废话不多,直接列举几种框架搭建方式,为了尽量向大家提供干货,本文直接从简介和手把手教搭建框架两方面来讲解,本文提到五种经典框架模式,学会这五种就很够了,分别是:状态机框架(State Machine)、生产者-消费者框架(Producer-Consumer)、主-从框架(Master-Slave)、事件驱动框架(Event-Driven)、分层架构(Layered Architecturep)。这个框架是基于状态机结构的。顾名思义“状态机”就是个“切换程序状态的机器”。本质是一个。

关注我,更多技术问题欢迎私聊~ 3112

HDU 3853 LOOPS 期望DP入门

HDU 3853 LOOPS 期望DP入门

Anonymous_jacklovecj的博客 469

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

HDU3853 LOOPS 概率DP数学期望

HDU3853 LOOPS 概率DP 题目大意: 给出一个n * m的矩阵,要求从左上角走到右下角,每次移动消耗两点能量,并且每次的移动方向是有概率的(回到自身,往右或者往下)。输入的矩阵中的每个位置有三个数,分别表示回到自身、向右移动、向下移动的概率,三者概率和为1,要求输出从左上角走到右下角需要消耗的能量值的期望。(测试数据可能有点问题,会出现回到自身的概率为1从而导致死循环的情况) 解题思路...

qq_43710979的博客 976

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

HDU 3853 LOOPS (概率DP)

HDU 3853 LOOPS (概率DP)http://acm.hdu.edu.cn/showproblem.php?pid=3853 题面: LOOPS Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/Others) Total Submission(s): 4567   

而濡木染 939

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

HDU 3853 LOOPS(概率dp 求期望)

HDU 3853 LOOPS(概率dp 求期望)

1256

HDU3853:LOOPS

又是被HDU针对的一天HDU3853:LOOPS题目大意思路代码~~又被HDU封印了~~ 题目大意 传送门 思路 我们可以设dp[i][j]dp[i][j]dp[i][j]表示(i,j)(i,j)(i,j)到终点的期望能量,那么dp[i][j]=dp[i][j+1]×pro[i][j][1](走到这个点的概率)+dp[i+1][j]×pro[i][j][2]+dp[i][j]×pro[i][j]...

nobody_like_you的博客 277

简单概率dp(期望)-hdu-3853-LOOPS

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3853 题目大意: 给一个r*c的矩阵,每个格子(x,y),用2魔法值就可以走一步,(可以到(x,y)、(x+1,y)、(x,y+1)),告诉每个格子的能到达的三个位置的概率,求从左上角到达右下角所需魔法值的期望。 解题思路: 简单期望dp. dp[i][j]表示从位置(i,j)到达终

cc_again的专栏 2374

HDU 3853 LOOPS:期望dp【网格型】

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3853 题意:   有一个n*m的网格。   给出在每个格子时:留在原地、向右走一格,向下走一格的概率。   每走一格会消耗2点体力。   问你从(1,1)到达终点(n,m)消耗体力的期望。 题解:   表示状态:     dp[i][j] = rest steps(剩余...

a1392136的博客 259

hdu 3853 LOOPS(期望)

http://acm.hdu.edu.cn/showproblem.php?pid=3853 求从【1,1】到【r,c】的所花power的期望,每走一步消耗的power是2,给出从[i,j]到[i,j],[i,j+1],[i+1][j]概率。 dp[i][j]表示从[i,j]到[r,c]的消耗power的期望,已知终态dp[r][c] = 0,然后逆推。 很难想的是当在原地的

1011

HDU 3853 LOOPS(概率dp求期望)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3853 Problem Description Akemi Homura is a Mahou Shoujo (Puella Magi/Magical Girl). Homura wants to help her friend Madoka save the world. But be...

1568

HDU 3853 LOOPS 概率DP 期望

题意:在(i,j)(i,j)处的点有rate(i,j,1)rate_{(i,j,1)}的概率留在(i,j)(i,j)处,有rate(i,j,2)rate_{(i,j,2)}的概率走向(i,j+1)(i,j+1)处,有rate(i,j,3)rate_{(i,j,3)}的概率走向(i+1,j)(i+1,j)处,走一步需要花费2,问从(1,1)(1,1)走到(n,m)(n,m)处花费的期望是多少?思路:期

NM的专栏 368

HDU 3853-LOOPS【期望DP】

题意:有一个R*C的迷宫,从(1,1)走到(R,C),每个格子给出停留在原地,向右走一格和向下走一格的概率,且每走一步需要2点能量,求最后所需要的能量期望。 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3853 思路:f[i][j] 就表示走到(i, j) 这个点的期望能量,那么转移方程不难想到,这题主要有两个需要注意的地方,一是停留在原地的花...

独钓门前月 656

LOOPS HDU - 3853 dp求期望值

问题: 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 cal...

HXX904的博客 333

hdu3853 LOOPS 概率dp求期望

题意:给定一个n*m的方格,给出相应( i , j ) 原地、往下 、往右走的概率,每走一格花费魔法值2,求从起始点(1,1)到(n,m)花费魔法值的期望 思路:设dp[ i ][ j ]为从(i , j)出发到达目标状态(n , m)所需魔法值的期望。dp[ i ][ j ]有3种转移方式: (1)dp[ i ][ j ] -------> dp[ i ][ j ],转移概率为p1; (2

AC_kereo的专栏 1355
上一篇: [HDU] 4405 Aeroplane chess 期望dp入门
下一篇: [HDU] 4336 Card Collector 期望dp
MaxMercer
博客等级 码龄10年 55粉丝 261原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值