zoukankan      html  css  js  c++  java
  • [HNOI2015]亚瑟王

    嘟嘟嘟


    翻某(些)人的做题记录看到这道题的。


    知道是期望dp,但就是没想出来,看题解后才知道是状态设的不好。“良好的状态是AC的一半啊……”
    我设的是dp[i][j]表示第(i)个人在(j)轮后出招的概率,而题解是(r)轮后,前(i)个人中有(j)个人出招的概率。
    剩下的我感觉题解讲的非常清楚,不必我多说,所以给个链接吧:大佬的题解


    听说这题有人被卡常,反正我是没有。非要卡的话,观察每次乘方的数,指数每次+1,所以可以继承上一次的乘方答案,从而省去快速幂。
    (不想卡就写了个(O(n ^ 2logn))的了)

    #include<cstdio>
    #include<iostream>
    #include<cmath>
    #include<algorithm>
    #include<cstring>
    #include<cstdlib>
    #include<cctype>
    #include<vector>
    #include<stack>
    #include<queue>
    using namespace std;
    #define enter puts("") 
    #define space putchar(' ')
    #define Mem(a, x) memset(a, x, sizeof(a))
    #define In inline
    typedef long long ll;
    typedef double db;
    const int INF = 0x3f3f3f3f;
    const db eps = 1e-8;
    const int maxn = 225;
    inline ll read()
    {
      ll ans = 0;
      char ch = getchar(), last = ' ';
      while(!isdigit(ch)) last = ch, ch = getchar();
      while(isdigit(ch)) ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar();
      if(last == '-') ans = -ans;
      return ans;
    }
    inline void write(ll x)
    {
      if(x < 0) x = -x, putchar('-');
      if(x >= 10) write(x / 10);
      putchar(x % 10 + '0');
    }
    
    int n, m;
    db p[maxn];
    int d[maxn];
    db dp[maxn][maxn];
    
    In db quickpow(db a, ll b)
    {
      db ret = 1;
      for(; b; b >>= 1, a *= a)
        if(b & 1) ret *= a;
      return ret;
    }
    
    int main()
    {
      int T = read();
      while(T--)
        {
          n = read(); m = read();
          for(int i = 1; i <= n; ++i) scanf("%lf", &p[i]), d[i] = read();
          dp[0][0] = 1;
          db ans = 0;
          for(int i = 1; i <= n; ++i)
    	for(int j = 0; j <= m; ++j)
    	  {
    	    dp[i][j] = dp[i - 1][j] * quickpow(1 - p[i], m - j);
    	    if(j) dp[i][j] += dp[i - 1][j - 1] * (1 - quickpow(1 - p[i], m - j + 1));
    	    ans += dp[i - 1][j] * (1 - quickpow(1 - p[i], m - j)) * d[i];
    	  }
          printf("%.10lf
    ", ans);
        }
      return 0;
    }
    
  • 相关阅读:
    20190211 模拟训练 A. 大猫咪
    如何诊断节点重启问题
    诊断 Grid Infrastructure 启动问题 (文档 ID 1623340.1)
    bzoj4025 二分图
    root.sh脚本支持checkpoints文件实现重复运行
    [IOI2018] seats 排座位
    最常见的 5 个导致节点重新启动、驱逐或 CRS 意外重启的问题 (文档 ID 1524455.1)
    [IOI2018] werewolf 狼人
    OCR/Vote disk 维护操作: (添加/删除/替换/移动) (文档 ID 1674859.1)
    [POI2011]ROT-Tree Rotations
  • 原文地址:https://www.cnblogs.com/mrclr/p/10374285.html
Copyright © 2011-2022 走看看