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: ...
随机推荐
- 【C#】课堂知识点#1
标准数字格式字符串 https://docs.microsoft.com/zh-cn/dotnet/standard/base-types/standard-numeric-format-string ...
- php底层源码之数组
数组key和value的限制条件 <?php $arr = array( 1 => 'a', "1" => "b", 1.5 => &q ...
- MySQL 5.7 多源复制实践
多源复制使用场景 数据分析部门会需要各个业务部门的部分数据做数据分析,这个时候就可以用到多源复制把各个主数据库的数据复制到统一的数据库中. 在从服务器进行数据汇总,如果我们的主服务器进行了分库分表的操 ...
- python练习:函数4
''' 1.定义一个func(name),该函数效果如下. assert func("lilei") = "Lilei" assert func("h ...
- .NET Core 使用ModelBinder去掉所有参数的空格
一.前言 通过各种姿势搜索都没搜到这方面的,唯一找到一个比较符合的,但是只适合简单类型,而且代码还没贴全,心累.. 然后查看官网和源码之后,发现继承并实现 IModelBinder和IModelBin ...
- JS中的原型对象与构造器
在Javascript中:原型对象是属于构造函数的,不属于实例:实例只能共享原型对象中的属性和方法(当然也可以有自己的属性和方法,或者覆盖原型中同名的属性和方法):构造器constructor属于原型 ...
- Android Service的有关总结
来自一位网友的评论 1.使用方式 startService 启动的服务 主要用于启动一个服务执行后台任务,不进行通信.停止服务使用stopService bindService 启动的服务 该方法启动 ...
- layer弹出层移动端组件
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name ...
- Ubuntu18.0 解决python虚拟环境中不同用户下或者python多版本环境中指定虚拟环境的使用问题
一. 不同用户下配置virtualenvwrapper的问题 问题描述: 安装virtualnev和virtualnevwrapper之后,在.bashrc进行virtualenvwrapper的相关 ...
- Link monitoring
参考:https://www.ibm.com/support/knowledgecenter/en/linuxonibm/com.ibm.linux.z.l0wlcb00/l0wlcb00_miimo ...