hdu 4576 概率dp **

题意: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.

hdu 4576 概率dp **

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-;
typedef long long ll;
#define cl(a) memset(a,0,sizeof(a))
#define ts printf("*****\n");
const int MAXN=;
int n,m,tt;
double dp[][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==&&m==&&l==&&r==)break;
dp[][]=;
for(i=;i<=n;i++) dp[][i]=;
int now=;
while(m--)
{
scanf("%d",&x);
for(i=;i<n;i++)
{
dp[now^][i]=;
}
for(i=;i<n;i++)
{
if(dp[now][i]==) continue;
dp[now^][((i-x)%n+n)%n]+=0.5*dp[now][i];
dp[now^][(i+x)%n]+=0.5*dp[now][i];
}
now^=;
}
double ans=;
for(i=l-;i<r;i++)
{
ans+=dp[now][i];
}
printf("%.4lf\n",ans);
}
}
上一篇:C#操作access和SQL server数据库代码实例


下一篇:Javascript初学篇章_7(DOM)