• HDU 4405 Aeroplane chess (期望DP)


    题意:从0开始,要跳到 n 这个位置,如果当前位置是一个飞行点,那么可以跳过去,要不然就只能掷骰子,问你要掷的次数数学期望,到达或者超过n。

    析:概率DP,dp[i] 表示从 i  这个位置到达 n 要掷的次数的数学期望。然后每次掷的数就是1-6,概率都相等为1/6,再特殊标记一下飞行点,那么就容易写过了,

    在的时候是必须飞过去,不能掷骰子。

    代码如下:

    #pragma comment(linker, "/STACK:1024000000,1024000000")
    #include <cstdio>
    #include <string>
    #include <cstdlib>
    #include <cmath>
    #include <iostream>
    #include <cstring>
    #include <set>
    #include <queue>
    #include <algorithm>
    #include <vector>
    #include <map>
    #include <cctype>
    #include <cmath>
    #include <stack>
    #include <sstream>
    #define debug() puts("++++");
    #define gcd(a, b) __gcd(a, b)
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    #define freopenr freopen("in.txt", "r", stdin)
    #define freopenw freopen("out.txt", "w", stdout)
    using namespace std;
    
    typedef long long LL;
    typedef unsigned long long ULL;
    typedef pair<int, int> P;
    const int INF = 0x3f3f3f3f;
    const LL LNF = 1e16;
    const double inf = 0x3f3f3f3f3f3f;
    const double PI = acos(-1.0);
    const double eps = 1e-8;
    const int maxn = 1e5 + 10;
    const int mod = 1000000007;
    const int dr[] = {-1, 0, 1, 0};
    const int dc[] = {0, 1, 0, -1};
    const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
    int n, m;
    const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    inline bool is_in(int r, int c){
      return r >= 0 && r < n && c >= 0 && c < m;
    }
    
    double dp[maxn];
    map<int, int> mp;
    
    int main(){
      while(scanf("%d %d", &n, &m) == 2 && m+n){
        mp.clear();
        memset(dp, 0, sizeof dp);
        for(int i = 0; i < m; ++i){
          int a, b;
          scanf("%d %d", &a, &b);
          mp[a] = b;
        }
        for(int i = n-1; i >= 0; --i)
          if(mp.count(i))  dp[i] += dp[mp[i]];
          else{
            for(int j = 1; j < 7; ++j)
              dp[i] += dp[i+j] / 6.0;
            dp[i] += 1.0;
          }
        printf("%.4f
    ", dp[0]);
      }
      return 0;
    }
    

      

  • 相关阅读:
    使用Python连接redis(redis作MQ使用)_Tister的空间_百度空间
    LTTng 2.0 Downloads | LTTng Project
    How to capture stdout in realtime with Python « SaltyCrane Blog
    python的线程锁机制_dominic_80ChinaUnix博客
    Collective Intelligence实战/阿拉克(Satnam Alag)图书卓越亚马逊 [集体智慧编程]
    查IP
    沃尔玛控股中国1号店
    HeidiSQL MySQL made easy
    groovy学习7groovy sql 雪霁霜飞 博客园
    数据集 (DataSet) groovy
  • 原文地址:https://www.cnblogs.com/dwtfukgv/p/6135449.html
Copyright © 2020-2023  润新知