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: ...
随机推荐
- SAS学习笔记14 利用SAS绘制地图(二)
笔记9讲过利用SAS绘制地图,这次接着讲 用中国各地(不含港澳台)的平均湿度数据来绘制地图 在地图上标出地名 宏%maplabel有9个参数,依次为:地图文件名.包含区域名称的数据集文件.输出的注释数 ...
- phc-winner-argon2、argon2-cffi安装使用方法
Argon2 is a password-hashing function created by by Alex Biryukov, Daniel Dinu, and Dmitry Khovratov ...
- (一)easyUI之第一个demo
一.下载 官网下载 : http://www.jeasyui.net/download/ 同时并下载官方中文API文档. 解压后的目录结构: 二.第一个demo 1 新建工程并导入包 2 ...
- (二)Lucene之根据关键字搜索文件
前提:在使用lucene进行搜索的时候,必须先生成索引文件,即必须先进行上一章节的案例,生成索引文件如下: 该索引文件为"segments"开头,如果没有该文件则说明没有索引文件则 ...
- pyodbc报错pyodbc.InterfaceError
connection = pyodbc.connect(r'Driver={SQL Server Native Client 11.0};Server=...;Database=...;Trusted ...
- springboot启动流程(三)Environment简介
所有文章 https://www.cnblogs.com/lay2017/p/11478237.html 简介 上一篇文章中,我们简单了解了一下SpringApplication的run方法的代码逻辑 ...
- JavaScript Drum kit
用 JavaScript 实现网页鼓乐器,相关的初始代码在 JavaScript30 官网和 GitHub 上已经存在.我把 sound 文件夹下的音频全部替换掉了,一些相关解释也直接在注释中标明. ...
- vue slot的使用(transform动画)
slot的说明就看vue的官方文档 但是有点模糊 理解: 是对组件的扩展,通过slot插槽向组件内部指定位置传递内容,通过slot可以父子传参: 解决什么问题:正常情况下,<Child&g ...
- 自适应高度文本框 react contenteditable
import React, { Component } from 'react'; import PropTypes from 'prop-types'; const reduceTargetKeys ...
- socket技术详解
https://blog.csdn.net/weixin_39634961/article/details/80236161 socket编程是网络常用的编程,我们通过在网络中创建socket关键字来 ...