HDU 4487 Maximum Random Walk(概率DP)

题目链接:点击打开链接

思路:概率DP, 用d[i][j][k]表示第i步, 走到j点, 走过的最大值为k的概率。  然后最后用概率乘以最右边走到的点就是期望, 期望相加就是答案。

细节参见代码:

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
using namespace std;
typedef long long ll;
typedef long double ld;
const ld eps = 1e-9, PI = 3.1415926535897932384626433832795;
const int mod = 1000000000 + 7;
const int INF = 0x3f3f3f3f;
// & 0x7FFFFFFF
const int seed = 131;
const ll INF64 = ll(1e18);
const int maxn = 200 + 10;
int T,n,m,id;
double d[2][maxn][maxn];
double a, b;
int main() {
    scanf("%d",&T);
    while(T--) {
        scanf("%d%d%lf%lf",&id,&n,&a,&b);
        int m = n;
        printf("%d ",id);
        n *= 2;
        int u = 0;
        memset(d[u], 0, sizeof(d[u]));
        d[u][m][m] = 1.0;
        for(int i = 0; i < m; i++) {
            memset(d[u^1], 0, sizeof(d[u^1]));
            for(int j = 1; j< n; j++) {
                for(int k = 1; k < n; k++) {
                    d[u^1][j-1][k] += d[u][j][k] * a;
                    d[u^1][j+1][max(k, j+1)] += d[u][j][k] * b;
                    d[u^1][j][k] += d[u][j][k] * (1.0 - a - b);
                }
            }
            u ^= 1;
        }
        double ans = 0;
        for(int i = 0; i <= n; i++) {
            for(int j = 0; j <= n; j++) {
                ans += d[u][i][j] * (j - m);
            }
        }
        printf("%.4f\n",ans);
    }
    return 0;
}
时间: 2024-10-20 07:34:30

HDU 4487 Maximum Random Walk(概率DP)的相关文章

HDU 4487 Maximum Random Walk 概率 dp

D - Maximum Random Walk Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 4487 Appoint description:  System Crawler  (2016-05-03) Description Consider the classic random walk: at each step, you ha

HDU 4487 Maximum Random Walk

Maximum Random Walk Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 756    Accepted Submission(s): 419 三维dp,一维的话根本没有办法开展,二维的话没办法保存当前位置或者最远位置,所以只能用三维的. 看不懂滚动数组之类的操作,只能傻傻的写. 具体内容在代码里标注了,三重循环,从i,j,

HDU 4865 Peter&#39;s Hobby --概率DP

题意:第i天的天气会一定概率地影响第i+1天的天气,也会一定概率地影响这一天的湿度.概率在表中给出.给出n天的湿度,推测概率最大的这n天的天气. 分析:这是引自机器学习中隐马尔科夫模型的入门模型,其实在这里直接DP就可以了 定义:dp[i][j]为第i天天气为j(0,1,2分别表示三个天气)的概率,path[i][j]记录路径,path[i][j] = k 意思是前一天天气为k时,这一天有最大的概率是天气j. 做一个三重循环,对于每天,枚举今天的天气,再在里面枚举昨天的天气,则有: dp[i][

HDU 4405 Aeroplane chess (概率DP求期望)

题意:有一个n个点的飞行棋,问从0点掷骰子(1~6)走到n点需要步数的期望 其中有m个跳跃a,b表示走到a点可以直接跳到b点. dp[ i ]表示从i点走到n点的期望,在正常情况下i点可以到走到i+1,i+2,i+3,i+4,i+5,i+6 点且每个点的概率都为1/6 所以dp[i]=(dp[i+1]+dp[i+2]+dp[i+3]+dp[i+4]+dp[i+5]+dp[i+6])/6  + 1(步数加一). 而对于有跳跃的点直接为dp[a]=dp[b]; #include<stdio.h>

hdu 4418 Time travel (概率dp 细节好多)

Time travel Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1366    Accepted Submission(s): 303 Problem Description Agent K is one of the greatest agents in a secret organization called Men in

hdu 5001 walk 概率dp入门题

Description I used to think I could be anything, but now I know that I couldn't do anything. So I started traveling. The nation looks like a connected bidirectional graph, and I am randomly walking on it. It means when I am at node i, I will travel t

HDU5001 Walk(概率DP)

A - Walk Time Limit:15000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 5001 Description I used to think I could be anything, but now I know that I couldn't do anything. So I started traveling. The nation loo

hdu 3076 ssworld VS DDD (概率dp)

///题意: /// A,B掷骰子,对于每一次点数大者胜,平为和,A先胜了m次A赢,B先胜了n次B赢. ///p1表示a赢,p2表示b赢,p=1-p1-p2表示平局 ///a赢得概率 比一次p1 两次p0*p1 三次 p0^2*p1,即A赢的概率为p1+p*p1+p^2*p1+...p^n*p1,n->无穷 ///即a_win=p1/(1-p);b_win=p2/(1-p); ///dp[i][j]表示a赢了j次,b赢了i次的概率 ///dp[i][j]=dp[i-1][j]*b_win+dp[

HDU 4050 wolf5x(动态规划-概率DP)

wolf5x Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 402    Accepted Submission(s): 248 Special Judge Problem Description There are n grids in a row. The coordinates of grids are numbered fro