您的位置:首页 > 其它

hdu 4576 概率dp **

2015-07-06 10:36 375 查看
题意:Michael has a telecontrol robot. One day he put the robot on a loop with n cells. The cells are numbered from 1 to n clockwise.



At
first the robot is in cell 1. Then Michael uses a remote control to
send m commands to the robot. A command will make the robot walk some
distance. Unfortunately the direction part on the remote control is
broken, so for every command the robot will chose a direction(clockwise
or anticlockwise) randomly with equal possibility, and then walk w cells
forward.
Michael wants to know the possibility of the robot stopping in the cell that cell number >= l and <= r after m commands.

链接:点我

时间上卡的有点紧

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
using namespace std;
#define MOD 1000000007
const int INF=0x3f3f3f3f;
const double eps=1e-5;
typedef long long ll;
#define cl(a) memset(a,0,sizeof(a))
#define ts printf("*****\n");
const int MAXN=220;
int n,m,tt;
double dp[2][MAXN];
int a[MAXN];
int main()
{
int i,j,k;
#ifndef ONLINE_JUDGE
freopen("1.in","r",stdin);
#endif
int x,l,r;
while(scanf("%d%d%d%d",&n,&m,&l,&r)!=EOF)
{
if(n==0&&m==0&&l==0&&r==0)break;
dp[0][0]=1;
for(i=1;i<=n;i++)    dp[0][i]=0;
int now=0;
while(m--)
{
scanf("%d",&x);
for(i=0;i<n;i++)
{
dp[now^1][i]=0;
}
for(i=0;i<n;i++)
{
if(dp[now][i]==0)   continue;
dp[now^1][((i-x)%n+n)%n]+=0.5*dp[now][i];
dp[now^1][(i+x)%n]+=0.5*dp[now][i];
}
now^=1;
}
double ans=0;
for(i=l-1;i<r;i++)
{
ans+=dp[now][i];
}
printf("%.4lf\n",ans);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: