zoukankan      html  css  js  c++  java
  • bzoj2688 Green Hackenbush

    (没有嘟嘟嘟)
    权限题,请各位自己想办法交。不过代码正确性是可以保证的,至于为啥那不能说。


    刚学完卡特兰数,就给我这种神题,我除了知道(n)个点的不同形态二叉树的数目是卡特兰数外,别的就不会了。
    所以又去学了博弈论(以前学过,弃了)。


    首先这道题叫“树上删边游戏”,然后有一个结论:一个节点的sg函数等于他的所有子树的sg函数+1的异或和。这有一篇相关博文:树上删边游戏及其拓展


    但毒瘤出题人不给树的形态,于是就出成了一道组合计数+博弈论+概率dp的神题。
    我反正是没搞出来,看了一篇题解,讲的特别清楚,遂放出链接,并且自己咕咕咕了。
    bzoj2688 Green Hackenbush(博弈+概率dp)

    #include<cstdio>
    #include<iostream>
    #include<cmath>
    #include<algorithm>
    #include<cstring>
    #include<cstdlib>
    #include<cctype>
    #include<vector>
    #include<stack>
    #include<queue>
    #include<assert.h>
    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 = 105;
    const int N = 127;
    In 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;
    }
    In void write(ll x)
    {
      if(x < 0) x = -x, putchar('-');
      if(x >= 10) write(x / 10);
      putchar(x % 10 + '0');
    }
    In void MYFILE()
    {
    #ifndef mrclr
      freopen("ha.in", "r", stdin);
      freopen("ha.out", "w", stdout);
    #endif
    }
    
    int n, Max, a[maxn];
    
    db cat[maxn], f[maxn][N + 2], g[maxn][N + 2];
    
    int main()
    {
      MYFILE();
      n = read();
      for(int i = 1; i <= n; ++i) a[i] = read(), Max = max(Max, a[i]);
      cat[0] = 1;
      for(int i = 1; i <= Max; ++i)
        for(int j = 0; j < i; ++j) cat[i] += cat[j] * cat[i - j - 1];
      //for(int i = 1; i <= Max; ++i) printf("#%.3lf ", cat[i]); enter;
      f[1][0] = 1;
      for(int i = 2; i <= Max; ++i)
        {
          for(int j = 0; j <= N; ++j) f[i][j + 1] = cat[i - 1] * f[i - 1][j] * 2;
          for(int j = 1; j < i - 1; ++j)
    	for(int x = 0; x <= N; ++x)
    	  for(int y = 0, tp; y <= N; ++y)
    	    if((tp = (x + 1) ^ (y + 1)) <= N)
    	      f[i][tp] += cat[j] * f[j][x] * cat[i - j - 1] * f[i - j - 1][y];
          for(int j = 0; j <= N; ++j) f[i][j] /= cat[i];
        }
      for(int i = 0; i <= N; ++i) g[1][i] = f[a[1]][i];
      for(int i = 1; i <= n; ++i)
        for(int j = 0; j <= N; ++j)
          for(int k = 0; k <= N; ++k)
    	g[i][j ^ k] += g[i - 1][j] * f[a[i]][k];
      printf("%.6lf
    ", 1 - g[n][0]);
      return 0;
    }
    
  • 相关阅读:
    联邦企业架构之CIO委员会的企业架构实施指南(下)
    Environment Detection环境检测工具设计与实现
    A Grain of Sand
    Java回顾之集合
    代码与工具(C++)
    搭建后台框架
    深入.NET程序集加载
    Express作为Node.js的开发框架
    使用NuGet发布自己的类库包(Library Package)
    新浪设计规范
  • 原文地址:https://www.cnblogs.com/mrclr/p/10907297.html
Copyright © 2011-2022 走看看