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.
![](https://oscdn.geek-share.com/Uploads/Images/Content/201908/25/4a8bcbc060fdf4f3aaa2d9f5b0a837bb.jpg)
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.
链接:点我
时间上卡的有点紧
![](https://oscdn.geek-share.com/Uploads/Images/Content/201908/25/4a8bcbc060fdf4f3aaa2d9f5b0a837bb.jpg)
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); } }
相关文章推荐
- EGL, GLX/WGL/AGL 和GL之间的关系
- Google HTML/CSS代码风格指南(中文版)
- URI和URLConnection类的区别
- hive一些思考
- 内存拷贝和字符串拷贝
- SAPLink详细体验
- kernel build
- JavaScript一个类继承中实现
- CSS属性选择器
- hive一些思考
- struts2的@Result annotation 如何添加params
- 伪分布模式 hive查询
- hive 连接查询sql对比效率
- hdu 1381 Crazy Search
- 获得日期的前几天或者后几天
- Java并发编程:synchronized
- getSharedPreferences 两个参数的含义
- appCode使用说明
- bootstrap媒体查询常用写法
- hive 连接查询sql对比效率