(没有嘟嘟嘟)

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




刚学完卡特兰数,就给我这种神题,我除了知道\(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;
}

bzoj2688 Green Hackenbush的更多相关文章

  1. 【BZOJ 2688】 2688: Green Hackenbush (概率DP+博弈-树上删边)

    2688: Green Hackenbush Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 42  Solved: 16 Description   ...

  2. 算法 - 剪枝游戏 - Green Hackenbush

    场景:给颗树,轮流剪掉一条枝,没枝可剪的人输. 题目:Deforestation | HackerRank 讲解:Games!: Green Hackenbush 哎,差点自己想出来答案,最后还是看了 ...

  3. I am Nexus Master!(虽然只是个模拟题。。。但仍想了很久!)

    I am Nexus Master!  The 13th Zhejiang University Programming Contest 参见:http://www.bnuoj.com/bnuoj/p ...

  4. UESTC 1852 Traveling Cellsperson

    找规律水题... Traveling Cellsperson Time Limit: 1000ms Memory Limit: 65535KB This problem will be judged ...

  5. UESTC 1851 Kings on a Chessboard

    状压DP... Kings on a Chessboard Time Limit: 10000ms Memory Limit: 65535KB This problem will be judged ...

  6. SPOJ 375. Query on a tree (树链剖分)

    Query on a tree Time Limit: 5000ms Memory Limit: 262144KB   This problem will be judged on SPOJ. Ori ...

  7. Robots on a grid(DP+bfs())

    链接:http://www.bnuoj.com/bnuoj/problem_show.php?pid=25585 Current Server Time: 2013-08-27 20:42:26 Ro ...

  8. Cellphone Typing 字典树

    Cellphone Typing Time Limit: 5000ms Memory Limit: 131072KB   This problem will be judged on UVA. Ori ...

  9. 第12届北师大校赛热身赛第二场 A.不和谐的长难句1

    题目链接:http://www.bnuoj.com/bnuoj/problem_show.php? pid=17121 2014-04-25 22:59:49 不和谐的长难句1 Time Limit: ...

随机推荐

  1. 少儿编程 | 01.Scratch 3.0简介

    欢迎参加这套Scratch3.0少儿编程课程的学习.本系列课程将通过视频和图文的方式进行(视频制作中,后续会发布).如果喜欢本系列课程,欢迎点击订阅关注或者转发. 这是本系列课程的第一课,主要是给家长 ...

  2. ELK 日志收集系统

    传统系统日志收集的问题 在传统项目中,如果在生产环境中,有多台不同的服务器集群,如果生产环境需要通过日志定位项目的Bug的话,需要在每台节点上使用传统的命令方式查询,这样效率非常底下. 通常,日志被分 ...

  3. 我对DES AES RSA的认识

    1.DES(Data Encryption Standard)算法:数据加密标准.是替换和置换细致而复杂的结合体,替换和置换一个接着一个,共循环16次.算法首先将明文分块,每块64位.密钥也是64位, ...

  4. 获取类的描述信息 DescriptionAttribute

    static void Main(string[] args) { var attrs = typeof(TestClass).GetCustomAttributes(typeof(System.Co ...

  5. c#入门学习笔记

    Hello World //打印语句 Console.WriteLine("Hello World"); //暂停 Console.ReadKey(); 数据类型 1.值类型 by ...

  6. python - pyxel 制作游戏

    之前看了一个项目,觉得还挺有意思的,是关于做一个像素风的游戏,现在,虚幻4,u3d,已经让游戏愈发的好看,好玩,曾经我们童年的像素风游戏,愈来愈少.所以,这里我们就回味下. Pyxel是一个pytho ...

  7. 一:项目简介(node express vue elementui axios)

    一:项目基本构造 ** 项目一共有 16 个页面,是一个电商网销项目,自己在网上的某网上找的一个要做的网站的设计图: 页面主要包括:  登录页 -- 注册页 -- 首页 -- 产品列表页 -- 产品详 ...

  8. Oracle数据库默认的data pump dir在哪

    转自:https://zhidao.baidu.com/question/921271686131558779.html 使用select * from dba_directories;可以查到,例如 ...

  9. Visual Studio 2017使用

    常用快捷方式 Ctrl + KK插入书签 取消书签Ctrl + KP 上一个书签Ctrl + KN 下一个数千Ctrl + F3 先一个关键词Shift + F3 上一个关键词 Ctrl + KC 添 ...

  10. Linux命令——shutdown、halt、poweroff、reboot、cal、date

    shutdown shutdown在关机的时候会通知所有用户 shutdown –r now 现在重启 shutdown now 现在关机 shutdown +5 过5分钟关机 shutdown –c ...