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;
}
bzoj2688 Green Hackenbush的更多相关文章
- 【BZOJ 2688】 2688: Green Hackenbush (概率DP+博弈-树上删边)
2688: Green Hackenbush Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 42 Solved: 16 Description ...
- 算法 - 剪枝游戏 - Green Hackenbush
场景:给颗树,轮流剪掉一条枝,没枝可剪的人输. 题目:Deforestation | HackerRank 讲解:Games!: Green Hackenbush 哎,差点自己想出来答案,最后还是看了 ...
- I am Nexus Master!(虽然只是个模拟题。。。但仍想了很久!)
I am Nexus Master! The 13th Zhejiang University Programming Contest 参见:http://www.bnuoj.com/bnuoj/p ...
- UESTC 1852 Traveling Cellsperson
找规律水题... Traveling Cellsperson Time Limit: 1000ms Memory Limit: 65535KB This problem will be judged ...
- UESTC 1851 Kings on a Chessboard
状压DP... Kings on a Chessboard Time Limit: 10000ms Memory Limit: 65535KB This problem will be judged ...
- SPOJ 375. Query on a tree (树链剖分)
Query on a tree Time Limit: 5000ms Memory Limit: 262144KB This problem will be judged on SPOJ. Ori ...
- 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 ...
- Cellphone Typing 字典树
Cellphone Typing Time Limit: 5000ms Memory Limit: 131072KB This problem will be judged on UVA. Ori ...
- 第12届北师大校赛热身赛第二场 A.不和谐的长难句1
题目链接:http://www.bnuoj.com/bnuoj/problem_show.php? pid=17121 2014-04-25 22:59:49 不和谐的长难句1 Time Limit: ...
随机推荐
- VS2013+WDK8.1 驱动开发环境配置
Windows Driver Kit 是一种完全集成的驱动程序开发工具包,它包含 WinDDK 用于测试 Windows 驱动器的可靠性和稳定性,本次实验使用的是 WDK8.1 驱动开发工具包,该工具 ...
- BZOJ3879 SvT(后缀树+虚树)
对反串建SAM得到后缀树,两后缀的lcp就是其在后缀树上lca的len值,于是每次询问对后缀树建出虚树并统计答案即可. #include<iostream> #include<cst ...
- Redis的bind的误区(转)
原文1:https://blog.csdn.net/cw_hello1/article/details/83444013 原文2:https://www.cnblogs.com/suiyueqiann ...
- Session共享问题---理论
随着网站访问量增加,初期的一台服务器已经完全不能支持业务,这个时候我们就需要增加服务器设备,来抗住请求的增量,如下所示: 负载均衡的目的本来就是要为了平均分配请求,所以没有固定第一次访问和第二次访问的 ...
- 3D数学基础_图形与游戏开发
https://blog.csdn.net/popy007/article/list/2?t=1& //向量计算相关文章 https://www.baidu.com/link?url=48C ...
- [转载]Java中继承、装饰者模式和代理模式的区别
[转载]Java中继承.装饰者模式和代理模式的区别 这是我在学Java Web时穿插学习Java设计模式的笔记 我就不转载原文了,直接指路好了: 装饰者模式和继承的区别: https://blog.c ...
- 关于vue.js的部分总结
1.MVVM和MVC的区别: MVVM:是Model-View-ViewModel的简写,即模型-视图-视图模型 模型:后端传递的数据 试图:所看到的页面 视图模型:mvvm模式的核心,它是连接vie ...
- 简单实现app使用PC图片
提一个很人性化的需求: 在自己的app里使用PC里的图片. 关键点:传输.怎么把图片从PC导入自己的APP. 因为iOS的封闭性,一般用户不能很方便把图片导入手机相册.笔者稍微想了下,实现功能其实也有 ...
- 阿里高级架构师教你如何使用Spring Cloud Ribbon重试请求
在微服务调用中,一些微服务圈可能调用失败,通过再次调用以达到系统稳定性效果,本文展示如何使用Ribbon和Spring Retry进行请求再次重试调用. 在Spring Cloud中,使用load b ...
- python 爬虫抓取 MOOC 中国课程的讨论区内容
一:selenium 库 selenium 每次模拟浏览器打开页面,xpath 匹配需要抓取的内容.可以,但是特别慢,相当慢.作为一个对技术有追求的爬虫菜鸡,狂补了一些爬虫知识.甚至看了 scrapy ...