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. org.apache.spark.launcher.Main源码分析

    public static void main(String[] argsArray) throws Exception { //org.apache.spark.launcher.Main chec ...

  2. C++clock()延时循环

    函数clock(),返回程序开始执行后所用的系统时间,但是有两个复制问题. 1.clock()返回时间的单位不一定是秒 2.该函数的返回类型在某些系统上可能是Long,也可能是unsigned lon ...

  3. Python变量常量及注释

    一.变量命名规则1.有字母.数字.下划线搭配组合而成2.不能以数字开头,更不能全为数字3.不能用Python的关键字4.不要太长5.名字要有意义6.不要用中文7.区分大小写8.采用驼峰体命名(多个单词 ...

  4. Python3 Tkinter-Listbox

    1.创建 from tkinter import * root=Tk() lb=Listbox(root) for item in ['python','tkinter','widget']: lb. ...

  5. POJ 1696 Space Ant(凸包变形)

    Description The most exciting space discovery occurred at the end of the 20th century. In 1999, scie ...

  6. HTML5form表单的相关知识总结

    首先在介绍HTML5form表单的新增内容之前,我总结了一下HTML的form表单的内容. <!DOCTYPE html> <html lang="en"> ...

  7. Notes of the scrum meeting(12.10)

    meeting time:20:00~20:30p.m.,December 10th,2013 meeting place:20号公寓前 attendees: 顾育豪                  ...

  8. Razor语法和Razor引擎大全

    一.Razor语法 1.Razor的标识符 解释:@字符被定义为Razor服务器代码块的标识符,后面的表示是服务器代码了.web form中使用<%%>中写服务器代码一个道理.在vs工具里 ...

  9. Window命令行工具操作文件

    1,cd 命令用来切换目录 2,mkdir用来创建文件夹 3,rmdir用来删除空文件夹 4,创建指定类型的文件 type nul>"文件名和后缀" 5,打开指定文件用sta ...

  10. open-stf 安装篇(linux)

       OpenSTF 百度MTC的远程真机调试 Testin的云真机 腾讯WeTest的云真机 阿里MQC的远程真机租用 什么是OpenSTF? OpenSTF是一个手机设备管理平台,可以对手机进行远 ...