HDU 4576

http://acm.hdu.edu.cn/showproblem.php?pid=4576

题意:给一个1-n的环,m次操作,每次操作顺时针或逆时针走w步,求最后落在[l,r]区间的概率

dp[i][j]表示第i步走到点j的概率,很裸的概率dp,i太大,需要滚动数组

时限4s,我的代码3984ms过的,有点悬

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>

using namespace std;

double dp[2][205];

int main() {
    int n, m, l, r;
    while(~scanf("%d %d %d %d", &n, &m, &l, &r)) {
        if(!n && !m && !l && !r) break;
        memset(dp, 0, sizeof(dp) );
        dp[0][0] = 1.0;
        int f = 0;
        while(m--) {
            int w;
            scanf("%d", &w);
            for(int i = 0; i < n; i++)
                dp[f ^ 1][i] = 0.0;
            for(int i = 0; i < n; i++) {
                dp[f ^ 1][(i + w) % n] += 0.5 * dp[f][i];
                dp[f ^ 1][(i - w + n) % n] += 0.5 * dp[f][i];
            }
            f ^= 1;
        }
        double ans = 0.0;
        for(int i = l; i <= r; i++)
            ans += dp[f][i-1];
        printf("%.4lf\n", ans);
    }
    return 0;
}

时间: 2024-08-24 12:13:43

HDU 4576的相关文章

[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 4576 简单概率 + 滚动数组DP(大坑)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4576 坑大发了,居然加 % 也会超时: 1 #include <cstdio> 2 #include <iostream> 3 #include <sstream> 4 #include <cmath> 5 #include <cstring> 6 #include <cstdlib> 7 #include <string>

HDU 4576 Robot (概率DP)

题意: 思路: #include<cstdio> #include<iostream> #include<cstring> #include<algorithm> using namespace std; double dp[3][300]; int main() { int n,m; int l,r; int i,j,k; double ans; int temp,now; while(scanf("%d%d%d%d",&n,&

HDU - 4576 Robot(概率dp+滚动数组)

题意:所有的格子围成一个圈,标号为1~n,若从格子1出发,每次指令告知行走的步数,但可能逆时针也可能顺时针走,概率都是1/2,那么问走了m次指令后位于格子l~r(1≤l≤r≤n)的概率. 分析: 1.因为m次指令后不知道会走到哪,会有很多种可能,但是知道从哪里出发,所以起始状态是已知的,在最初的状态,位于格子1是必然的,概率为1. 2.本题应用滚动数组,因为每次指令后都会延伸出无数种可能,这些可能是在前一种状态的基础上延伸的,而且延伸过后前一种状态的值不再有意义,完全可以被当前状态所覆盖. 3.

HDU 4576 Robot

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

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.

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.

dp题目列表

10271 - Chopsticks 10739 - String to Palindrome 10453 - Make Palindrome 10401 - Injured Queen Problem 825 - Walking on the Safe Side 10617 - Again Palindrome 10201 - Adventures in Moving - Part IV 11258 - String Partition 10564 - Paths through the Ho