Maximum Random Walk(概率dp)
题意:
走n步,给出每步向左走概率l,向右走概率r,留在原地的概率 1-l-r,求能达到的最远右边距离的期望。
分析;
开始按期望逆求的方式分析,但让求的就是右边界没法退,懵了一会,既然逆着不能求,就先正着求概率,再根据期望的定义来求,试试行吗,想了想状态,dp[i][j][k],表示走了i步当前位置是j最远右边界是k时的概率,因为可能位置是负的所以位置都加上n。
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <complex>
#include <cassert>
#include <utility>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
#define lson l,m,rt<<1
#define pi acos(-1.0)
#define rson m+1,r,rt<<11
#define All 1,N,1
#define N 110
#define read freopen("in.txt", "r", stdin)
const ll INFll = 0x3f3f3f3f3f3f3f3fLL;
const int INF= 0x7ffffff;
const int mod = ;
double dp[N][*N][N],l,r;
int main()
{
int n,o,t;
scanf("%d",&t);
while(t--){
scanf("%d%d%lf%lf",&o,&n,&l,&r);
memset(dp,,sizeof(dp));
dp[][n][n]=;
for(int i=;i<n;++i){
for(int j=;j<=*n;++j)
for(int k=j;k<=*n;++k)
{
dp[i+][j][k]+=dp[i][j][k]*(-l-r);
dp[i+][j-][k]+=dp[i][j][k]*l;
if(j+>k)
dp[i+][j+][k+]+=dp[i][j][k]*r;
else
dp[i+][j+][k]+=dp[i][j][k]*r;
}
}
//期望的定义
double total=0.0;
for(int j=;j<=*n;++j)
for(int k=j;k<=*n;++k)
total+=dp[n][j][k]*(k-n);
printf("%d %.4lf\n",o,total);
}
return ;
}
Maximum Random Walk(概率dp)的更多相关文章
- hdu 4579 Random Walk 概率DP
思路:由于m非常小,只有5.所以用dp[i]表示从位置i出发到达n的期望步数. 那么dp[n] = 0 dp[i] = sigma(dp[i + j] * p (i , i + j)) + 1 . ...
- HDU 4487 Maximum Random Walk
Maximum Random Walk Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- Hdu 5001 Walk 概率dp
Walk Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5001 Desc ...
- hdu5001 Walk 概率DP
I used to think I could be anything, but now I know that I couldn't do anything. So I started travel ...
- HDU - 5001 Walk(概率dp+记忆化搜索)
Walk I used to think I could be anything, but now I know that I couldn't do anything. So I started t ...
- HDU 5781 ATM Mechine (概率DP)
ATM Mechine 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5781 Description Alice is going to take ...
- ZOJ 3822 Domination(概率dp 牡丹江现场赛)
题目链接:problemId=5376">http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5376 Edward ...
- 从Random Walk谈到Bacterial foraging optimization algorithm(BFOA),再谈到Ramdom Walk Graph Segmentation图分割算法
1. 从细菌的趋化性谈起 0x1:物质化学浓度梯度 类似于概率分布中概率密度的概念.在溶液中存在不同的浓度区域. 如放一颗糖在水盆里,糖慢慢溶于水,糖附近的水含糖量比远离糖的水含糖量要高,也就是糖附近 ...
- Domination(概率DP)
Domination 题目链接:https://odzkskevi.qnssl.com/9713ae1d3ff2cc043442f25e9a86814c?v=1531624384 Edward is ...
随机推荐
- XML中如何使用schema
Schema简介 DTD的语法相当复杂,并且它不符合XML文件的标准,自成一个体系,W3C定义的Schema用来代替DTD. chema相对于DTD的明显好处是XML Schema文档本身也是XML文 ...
- Android中数据存储之SharedPreferences
import android.content.Context; import android.content.SharedPreferences; import android.content.Sha ...
- 套题T6
过节(festival.cpp/c/pas) Dxy帮老师们过教师节的时候需要购买礼物.货架上有n 种礼物,每种礼物有不同的个数.每种礼物有价值和花费两种属性,帮他算出最大可以得到的价值.M是带的钱数 ...
- My_Plan
离清北夏令营不远了,今天时间也不太多了,貌似并不够我写一道题 所以就先挖个坑制定个计划啦 从5.10到5.20 先制定十天的计划吧 1.考试题的每道题目都要改出来并做总结 2.数位DP练习(十道+总结 ...
- 李洪强iOS开发之OC语言description方法和sel
OC语言description方法和sel 一.description方法 Description方法包括类方法和对象方法.(NSObject类所包含) (一)基本知识 -description(对象 ...
- Android handler.obtainMessage()
在handler.obtainMessage()的参数是这样写的: Message android.os.Handler.obtainMessage(int what, int arg1, int a ...
- proc_dir_entry
struct proc_dir_entry { unsigned int low_ino; unsigned short namelen; const cha ...
- Hibernate的一个注释 @Transient
@Transient表示该属性并非一个到数据库表的字段的映射,ORM框架将忽略该属性. 如果一个属性并非数据库表的字段映射,就务必将其标示为@Transient,否则,ORM框架默认其注解为@Basi ...
- android的ScaleGestureDetector缩放类详解
文章由多出组合,它们来自: http://elvajxw.iteye.com/blog/1308452 http://www.cnblogs.com/lknlfy/archive/2012/03/11 ...
- 函数buf_read_page_low
/********************************************************************//** Low-level function which r ...