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\n", 1 - g[n][0]);
  return 0;
}

转载于:https://www.cnblogs.com/mrclr/p/10907297.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值