D - Maximum Random Walk

/*
n^3的Dp,2min的时限。
比赛的时候题目意思YY错误...然后推了半天...
概率题写的太少...题目意思都理解不了的痛...
dp[k][i][j] 定义:从当前位置i开始走到最右边位置为j的概率

dp转移 :

	往右走:
		1.如果i+1>j。dp[next][i+1][i+1]+=dp[now][i][j]*R。
		2.如果i+1<=j。dp[next][i+1][j]+=dp[now][i][j]*R。
	往左走:
	          dp[next][i-1][j]+=dp[now][i][j]*L。

	不走:
	          dp[next][i][j]+=dp[now][i][j]*(1-L-R)。

*/

//#pragma comment(linker, "/STACK:167772160")
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <ctime>
#include <cmath>
#include <cassert>
//#include <fstream>
#include <stack>
#include <cctype>
#define MP make_pair
#define PB push_back
#define SZ(x) (int)x.size()
#define INF 1<<29
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define L(x) x<<1
#define R(x) x<<1|1
#if(_WIN32||__WIN32__)
    #define LL __int64
    #define ll I64
#else
    #define LL long long
#endif
//#define Local

using namespace std;
double f[3][2100][2100];

double process(int n,double L,double R)
{
	double stop=1-L-R;
	memset(f,0,sizeof(f));
	int now=0;
	f[0][n][n]=1;
	for(int k=0;k<n;k++)
	{
		int next=now^1;
		memset(f[next],0,sizeof(f[next]));
		for(int i=0;i<=n+n;i++)
		{
			for(int j=n;j<=n+n;j++)
			{
				if(f[now][i][j]>0)
				{
					if(i+1>j)
						f[next][i+1][i+1]+=f[now][i][j]*R;
					else
						f[next][i+1][j]+=f[now][i][j]*R;
					if(i>0)
						f[next][i-1][j]+=f[now][i][j]*L;
					f[next][i][j]+=f[now][i][j]*stop;
				}
			}
		}
		now=next;
	}
	double ans=0;
	for(int i=0;i<=n+n;i++)
		for(int j=n+1;j<=n+n;j++)
				ans+=f[now][i][j]*(j-n);
	return ans;
}

int main()
{
	int T;
	scanf("%d",&T);
	while(T--)
	{
		int Case,n;
		double L,R;
		scanf("%d %d %lf %lf",&Case,&n,&L,&R);
		printf("%d %.4f\n",Case,process(n,L,R));
	}
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值