Robot

Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 102400/102400 K (Java/Others)
Total Submission(s): 5363    Accepted Submission(s): 1584

Problem Description
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.

 
Input
There are multiple test cases. 
Each test case contains several lines.
The first line contains four integers: above mentioned n(1≤n≤200) ,m(0≤m≤1,000,000),l,r(1≤l≤r≤n).
Then m lines follow, each representing a command. A command is a integer w(1≤w≤100) representing the cell length the robot will walk for this command.  
The input end with n=0,m=0,l=0,r=0. You should not process this test case.
 
Output
For each test case in the input, you should output a line with the expected possibility. Output should be round to 4 digits after decimal points.
 
Sample Input
3 1 1 2
1
5 2 4 4
1
2
0 0 0 0
 
Sample Output
0.5000
0.2500
 
Source
 

题意:

有长度为n的环,有m次操作,每次输入一个数w,可以选择顺时针或者逆时针走w步,问最后停在l区间[l,r]的概率。最初在1点。

输入n,m,l,r;

代码:

//这一步的状态只有上一步的状态决定,可列转移方程,但显然要用滚动数组优化。
//注意的是中间过程中有太多的取模运算,直接算会超时所以先预处理出来取模的值再算
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int n,m,l,r,mp[];
double dp[][];
int main()
{
while(scanf("%d%d%d%d",&n,&m,&l,&r)==){
if(n==&&m==&&l==&&r==) break;
for(int i=;i<=;i++) mp[i]=i%n;
int x;
l--;r--;
memset(dp,,sizeof(dp));
dp[][]=;
for(int i=;i<=m;i++){
int I=i&;
scanf("%d",&x);
x%=n;
for(int j=;j<n;j++){
int tmp=mp[j+x];
dp[I][tmp]+=dp[!I][j]*0.5;
tmp=mp[j+(n-x)];
dp[I][tmp]+=dp[!I][j]*0.5;
}
memset(dp[!I],,sizeof(dp[!I]));
}
double sum=;
int I=m&;
for(int i=l;i<=r;i++)
sum+=dp[I][i];
printf("%.4lf\n",sum);
}
return ;
}

HDU 4576 DP的更多相关文章

  1. hdu 3016 dp+线段树

    Man Down Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total S ...

  2. HDU 5928 DP 凸包graham

    给出点集,和不大于L长的绳子,问能包裹住的最多点数. 考虑每个点都作为左下角的起点跑一遍极角序求凸包,求的过程中用DP记录当前以j为当前末端为结束的的最小长度,其中一维作为背包的是凸包内侧点的数量.也 ...

  3. HDU 4576 简单概率 + 滚动数组DP(大坑)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4576 坑大发了,居然加 % 也会超时: #include <cstdio> #includ ...

  4. hdu 4576 (简单dp+滚动数组)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4576 题意:给出1~n的环,m个操作,每次能顺时针或逆时针走w步,询问最后在l~r这段区间内概率.(1 ...

  5. hdu 4576(概率dp+滚动数组)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4576 思路:由于每次从某一位置到达另一位置的概率为0.5,因此我们用dp[i][j]表示第i次操作落在 ...

  6. HDU 4576 Robot (概率DP)

    暴力DP求解太卡时间了...........写挫一点就跪了 //hdu robot #include <cstdio> #include <iostream> #include ...

  7. hdu 4576 概率dp **

    题意:Michael has a telecontrol robot. One day he put the robot on a loop with n cells. The cells are n ...

  8. HDU 4576 Robot(概率dp)

    题目 /*********************复制来的大致题意********************** 有N个数字,M个操作, 区间L, R. 然后问经过M个操作后落在[L, R]的概率. * ...

  9. hdu 4576(简单概率dp | 矩阵优化)

    艰难的一道题,体现出菜菜的我... 首先,先吐槽下. 这题到底出题人是怎么想的,用普通概率dp水过??? 那为什么我概率dp写的稍微烂点就一直tle?  感觉很不公平.大家算法都一致,因为我程序没有那 ...

随机推荐

  1. Git版本库工作流程图想

    对照廖雪峰的教程,发现有很多难以理解的地方,画了一个图想方便以后参考 首先两个基本命令反应了版本库最本质的工作流程,后面的命令其实都基于此git add 把文件修改添加到暂存区git commit 在 ...

  2. Educational Codeforces Round 32 Problem 888C - K-Dominant Character

    1) Link to the problem: http://codeforces.com/contest/888/problem/C 2) Description: You are given a ...

  3. 【转载】android 常用开源框架

    对于Android初学者以及对于我们菜鸟,这些大神们开发的轻量级框架非常有用(更别说开源的了). 下面转载这10个框架的介绍:(按顺序来吧没有什么排名). 一.  Afinal 官方介绍: Afina ...

  4. 基于spec评论“欢迎来怼”团队Alpha版作品

    “欢迎来怼”团队的作品是手机版博客园 1.获取此博客园app的方式——二维码 通过扫描二维码的方式下载app,这是当今比较流行的方式,适合广大手机的使用者——青少年的使用习惯. 2.点击图标,进入该a ...

  5. android在程序崩溃时Catch异常并处理

    Android系统的"程序异常退出",给应用的用户体验造成不良影响.为了捕获应用运行时异常并给出友好提示,便可继承UncaughtExceptionHandler类来处理.通过Th ...

  6. windows批处理学习(字符换操作)---04

    转自:https://www.cnblogs.com/DswCnblog/p/5432326.html 1.截取字符串 截取字符串可以说是字符串处理功能中最常用的一个子功能了,能够实现截取字符串中的特 ...

  7. SQL SERVER技术内幕之10 可编程对象

    一.变量 变量用于临时保存数据值,以供在声明它们的同一批处理语句中引用.例如,以下代码先声明一个数据类型为INT的变量@i,再将它赋值为10; DECLARE @i as INT; SET @i = ...

  8. QT分析之调试跟踪系统

    原文地址:http://blog.163.com/net_worm/blog/static/127702419201002004518944/ 在我们前面的分析中,经常看到qWarning()和qDe ...

  9. 新建maven工程问题001

    这周一直在研究SpringMVC+Mybatis,有些心得,记录一下. Ⅰ:建maven遇到的问题. 1.1 新建maven时选中[Create a simple project]这样,后面[Pack ...

  10. DELPHI dbgrid 选中的是第几行 怎么判断?

    使用DataSource.DataSet.RecNo可以得到dbgrid选中的是第几行,示例代码如下: procedure TForm1.btn1Click(Sender: TObject); beg ...