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. 【转】MMORPG游戏服务器技能系统设计:表格字段与技能程序框架

    本文主要从一个程序员的角度阐述一下mmorpg服务器技能系统的程序框架设计,最近在做这个,就当做一个总结吧,其中某些概念可能没有解释清楚,欢迎大家拍砖讨论~ 技能其实是战斗系统的一个组成部分,战斗基本 ...

  2. [Clr via C#读书笔记]Cp3共享程序集和强命名程

    Cp3共享程序集和强命名程序集 私有方式部署+全局方式部署:弱命名程序集+强命名程序集 强命名程序集使用发布者的公钥私钥进行签名,唯一标识发布者. 共享dll被全部复制到System32中 强命名程序 ...

  3. usb_modeswitch移植

    usb_modeswitch移植 交叉工具链安装 交叉编译安装libsub库 交叉编译安装lib-compat-x.x.x 交叉编译安装usb_modeswitch 交叉编译工具链 为了使编译的程序可 ...

  4. HDU 4617 Weapon(三维几何)

    Problem Description Doctor D. are researching for a horrific weapon. The muzzle of the weapon is a c ...

  5. LintCode-159.寻找旋转排序数组中的最小值

    寻找旋转排序数组中的最小值 假设一个旋转排序的数组其起始位置是未知的(比如0 1 2 4 5 6 7 可能变成是4 5 6 7 0 1 2). 你需要找到其中最小的元素. 你可以假设数组中不存在重复的 ...

  6. iOS- iOS 和 Android 的后台推送原理各是什么?有什么区别?

    iOS 的推送iOS 在系统级别有一个推送服务程序使用 5223 端口.使用这个端口的协议源于 Jabber 后来发展为 XMPP ,被用于 Gtalk 等 IM 软件中.所以, iOS 的推送,可以 ...

  7. 软工网络15团队作业4——Alpha阶段敏捷冲刺-2

    一.当天站立式会议照片: 二.项目进展 昨天已完成的工作: 微信公众号平台注册"小程序"的账号; 下载微信官方的小程序开发工具,这个是编辑小程序和上传审核小程序必须的工具; 大家一 ...

  8. 软工网络15团队作业4——Alpha阶段敏捷冲刺-4

    一.当天站立式会议照片: 二.项目进展 昨天已完成的工作: 完成程序副界面的设计与信息的输入统计 明天计划完成的工作: 日期等细致信息的处理 工作中遇到的困难: 对微信小程序开发的代码构成有了一些了解 ...

  9. vue服务端渲染axios预取数据

    首先是要参考vue服务端渲染教程:https://ssr.vuejs.org/zh/data.html. 本文主要代码均参考教程得来.基本原理如下,拷贝的原文教程. 为了解决这个问题,获取的数据需要位 ...

  10. ping traceroute原理

    ping命令工作原理 ping命令主要是用于检测网络的连通性. Ping命令发送一个ICMP请求报文给目的IP,然后目的IP回复一个ICMP报文. 原理:网络上的机器都有唯一确定的IP地址,我们给目标 ...