/*
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;
}
D - Maximum Random Walk
最新推荐文章于 2019-03-27 20:50:40 发布