HDU 4576 Robot(概率dp)

Robot

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

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

分析

code

 1 #include<cstdio>
 2 #include<algorithm>
 3 #include<cstring>
 4
 5 using namespace std;
 6
 7 double f[2][210];
 8 // f[i][j]到第i次操作,位置j上的概率
 9
10 int main() {
11
12     int n,m,l,r;
13     while (~scanf("%d%d%d%d",&n,&m,&l,&r) && n+m+l+r) {
14         memset(f,0,sizeof(f));
15         f[0][1] = 1.0;
16         int cur = 0;
17         for (int w,i=1; i<=m; ++i) {
18             scanf("%d",&w);
19             w = w%n;
20             cur = cur^1;
21             for (int k=1; k<=n; ++k) {
22                 f[cur][k] = f[cur^1][k+w>n?k+w-n:k+w]/2.0 + f[cur^1][k-w<1?k-w+n:k-w]/2.0;
23             }
24         }
25         double ans = 0.0;
26         for (int i=l; i<=r; ++i) ans += f[cur][i];
27         printf("%.4lf\n",ans);
28     }
29     return 0;
30 }

原文地址:https://www.cnblogs.com/mjtcn/p/8582100.html

时间: 2024-10-10 10:34:08

HDU 4576 Robot(概率dp)的相关文章

HDU 4576 Robot 概率DP 水题

Robot Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 102400/102400 K (Java/Others)Total Submission(s): 3851    Accepted Submission(s): 1246 Problem Description Michael has a telecontrol robot. One day he put the robot on a loop with n cells.

[ACM] HDU 4576 Robot (概率DP,滚动数组)

Robot 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 ro

HDU 4576 Robot(概率题)

Robot 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 ro

hdu 4870 Rating(概率DP&amp;高数消元)

Rating Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 714    Accepted Submission(s): 452 Special Judge Problem Description A little girl loves programming competition very much. Recently, she

HDU 4035Maze(概率DP)

HDU 4035   Maze 体会到了状态转移,化简方程的重要性 题解转自http://blog.csdn.net/morgan_xww/article/details/6776947 /** dp求期望的题. 题意: 有n个房间,由n-1条隧道连通起来,实际上就形成了一棵树, 从结点1出发,开始走,在每个结点i都有3种可能: 1.被杀死,回到结点1处(概率为ki) 2.找到出口,走出迷宫 (概率为ei) 3.和该点相连有m条边,随机走一条 求:走出迷宫所要走的边数的期望值. 设 E[i]表示

HDU 3853 LOOPS (概率dp)

LOOPS Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/Others) Total Submission(s): 2931    Accepted Submission(s): 1209 Problem Description Akemi Homura is a Mahou Shoujo (Puella Magi/Magical Girl). Homura wants to help

HDU 4089 Activation (概率dp 好题 + 难题)

Activation Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1842    Accepted Submission(s): 689 Problem Description After 4 years' waiting, the game "Chinese Paladin 5" finally comes out.

HDU - 1099 - Lottery - 概率dp

http://acm.hdu.edu.cn/showproblem.php?pid=1099 最最简单的概率dp,完全是等概率转移. 设dp[i]为已有i张票,还需要抽几次才能集齐的期望. 那么dp[n]=0,因为我们已经集齐了. \[dp[i]=(\frac{i}{n}*dp[i]+\frac{n-i}{n}*dp[i+1])+1\] 移项得答案. 然后写个分数类,注意约分. #include<bits/stdc++.h> using namespace std; typedef long

HDU 4599 Dice (概率DP+数学+快速幂)

题意:给定三个表达式,问你求出最小的m1,m2,满足G(m1) >= F(n), G(m2) >= G(n). 析:这个题是一个概率DP,但是并没有那么简单,运算过程很麻烦. 先分析F(n),这个用DP来推公式,d[i],表示抛 i 次连续的点数还要抛多少次才能完成.那么状态转移方程就是 d[i] = 1/6*(1+d[i+1]) + 5/6*(1+d[1]), 意思就是说在第 i 次抛和上次相同的概率是1/6,然后加上上次抛的和这一次,再加上和上次不同的,并且又得从第1次开始计算. 边界就是

hdu 5001 walk 概率dp入门题

Description I used to think I could be anything, but now I know that I couldn't do anything. So I started traveling. The nation looks like a connected bidirectional graph, and I am randomly walking on it. It means when I am at node i, I will travel t