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: ...
随机推荐
- Scratch2.0教材(9)——合体大变身
教材说明 ——————— 1.本教材共96节课,适用于3-5年级.40人.40分钟的课堂: 2.初期我会把每节课的代码控制在10行以内,后期再逐渐增加: 3.欢迎提意见. 课程摘要 ——————— [ ...
- Tomcat安装及其目录结构介绍
Tomcat服务器是一个免费的开放源代码的Web应用服务器,属于轻量级应用服务器,在中小型系统和并发访问用户不是很多的场合下被普遍使用,是开发和调试JSP程序的首选. Tomcat的安装版本有绿色解压 ...
- Thymeleaf 模板使用 Error resolving template "/home", template might not exist or might not be accessible by any of the
和属性文件中thymeleaf模板的配置相关 1.配置信息 spring.thymeleaf.prefix=classpath:/templates/ spring.thymeleaf.suffix= ...
- .NetCore如何使用ImageSharp进行图片的生成
ImageSharp是对NetCore平台扩展的一个图像处理方案,以往网上的案例多以生成文字及画出简单图形.验证码等方式进行探讨和实践. 今天我分享一下所在公司项目的实际应用案例,导出微信二维码图片, ...
- buffer 与 cache 的区别
Buffer 和 Cache buffer 和 cache 同样作为缓存,他们之间有什么区别呢? 简单来说,buffer 是即将要写入磁盘的缓存,而 cache 是从磁盘中读出来放到缓存的 参考来自: ...
- java调用.net的webservice接口
要调用webservice,首先得有接口,用已经写好的接口地址在myEclipse的目标project中,右键->new web service client-> 选择JAX-WS方式,点 ...
- 11.ForkJoinPool 分支/合并框架 (工作窃取)
/*ForkJoinPool 分支/合并框架 (工作窃取)*/ Fork/Join 框架:就是在必要的情况下,将一个大任务,进行拆分(fork) 成若干个小任务(拆到给出的临界值为止),再将一个个的小 ...
- dubbo线程池作用于接口而不是方法
记一次线上dubbo服务超时和线程池满问题排查 可能调用的接口没问题,但是该服务中的其他接口占用完了线程池,导致调用超时被拒绝处理.
- Java Socket编程----网络基础
详见:https://www.cnblogs.com/rocomp/p/4790340.html Java最初是作为网络编程语言出现的,其对网络提供了高度的支持,使得客户端和服务器的沟通变成了现实,而 ...
- APP中的第三方“支付”功能测试建议
目前市场上APP中带有支付功能的产品有非常多,那么APP中带有第三方支付功能的产品在这一模块该如何测试才尽可能的确保测试完整性. 正常流程: 正常使用支付宝.微信.银行卡(目前使用最多的第三方支付方式 ...