http://codeforces.com/problemset/problem/538/E

题目大意:

给出一棵树,叶子节点上都有一个值,从1-m。有两个人交替从根选择道路,先手希望到达的叶子节点尽量大,后手希望到达的叶子节点尽量小,叶子节点的放置方案任意。两个人都足够聪明,能够得到的最大值和最小值分别是多少。

思路:

先考虑最大的情况

考虑dp[i]代表i这个节点能达到的最大的数字在这个子树中排第几。

如果当前是先手操作,那么他肯定会往最大的那个子树的方向走,即dp[u]=min(dp[v])

如果当前是后手操作,那么他肯定往最小的走,即dp[u]=Σdp[v],这样就走到了最差子树的最大数字去了。

然后最小的情况类似

 #include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<iostream>
int tot,go[],next[],first[];
int n,f1[],f2[],pd[],son[],deep[];
int read(){
int t=,f=;char ch=getchar();
while (ch<''||ch>''){if (ch=='-') f=-;ch=getchar();}
while (''<=ch&&ch<=''){t=t*+ch-'';ch=getchar();}
return t*f;
}
void insert(int x,int y){
tot++;
go[tot]=y;
next[tot]=first[x];
first[x]=tot;
}
void add(int x,int y){
insert(x,y);
insert(y,x);
}
void dfs(int x,int fa){
int pdd=;
for (int i=first[x];i;i=next[i]){
int pur=go[i];
if (pur==fa) continue;
pdd=;
deep[pur]=deep[x]+;
dfs(pur,x);
son[x]+=son[pur];
}
if (!pdd) son[x]=,pd[x]=;
}
void dfs1(int x,int fa){
if (pd[x]==) {
f1[x]=;
return;
}
if (deep[x]%){
f1[x]=0x7fffffff;
for (int i=first[x];i;i=next[i]){
int pur=go[i];
if (pur==fa) continue;
dfs1(pur,x);
f1[x]=std::min(f1[x],f1[pur]);
}
}else{
f1[x]=;
for (int i=first[x];i;i=next[i]){
int pur=go[i];
if (pur==fa) continue;
dfs1(pur,x);
f1[x]+=f1[pur];
}
}
}
void dfs2(int x,int fa){
if (pd[x]==) {
f2[x]=;
return;
}
if (deep[x]%){
f2[x]=;
for (int i=first[x];i;i=next[i]){
int pur=go[i];
if (pur==fa) continue;
dfs2(pur,x);
f2[x]+=f2[pur];
}
}else{
f2[x]=0x7fffffff;
for (int i=first[x];i;i=next[i]){
int pur=go[i];
if (pur==fa) continue;
dfs2(pur,x);
f2[x]=std::min(f2[x],f2[pur]);
}
}
}
int main(){
n=read();
for (int i=;i<n;i++){
int x=read(),y=read();
add(x,y);
}
deep[]=;
dfs(,);
dfs1(,);
printf("%d ",son[]-f1[]+);
dfs2(,);
printf("%d\n",f2[]);
return ;
}

Codeforces 538E Demiurges Play Again(博弈DP)的更多相关文章

  1. Codeforces Round #222 (Div. 1) 博弈 + dp

    一般这种要倒着来. #include<bits/stdc++.h> #define LL long long #define fi first #define se second #def ...

  2. HDU 5623 KK's Number (博弈DP)

    KK's Number 题目链接: http://acm.hust.edu.cn/vjudge/contest/121332#problem/K Description Our lovely KK h ...

  3. 博弈dp 以I Love this Game! POJ - 1678 为例

    写在前面的话 知识基础:一些基础的博弈论的方法,动态规划的一些知识 前言:博弈论就是一些关于策略或者游戏之间的最优解,动态规划就是对于一些状态之间转移的一些递推式(or 递归),dp分为很多很多种,比 ...

  4. 博弈dp入门 POJ - 1678 HDU - 4597

    本来博弈还没怎么搞懂,又和dp搞上了,哇,这真是冰火两重天,爽哉妙哉. 我自己的理解就是,博弈dp有点像对抗搜索的意思,但并不是对抗搜索,因为它是像博弈一样,大多数以当前的操作者来dp,光想是想不通的 ...

  5. [Codeforces 865C]Gotta Go Fast(期望dp+二分答案)

    [Codeforces 865C]Gotta Go Fast(期望dp+二分答案) 题面 一个游戏一共有n个关卡,对于第i关,用a[i]时间通过的概率为p[i],用b[i]通过的时间为1-p[i],每 ...

  6. [CodeForces - 1225E]Rock Is Push 【dp】【前缀和】

    [CodeForces - 1225E]Rock Is Push [dp][前缀和] 标签:题解 codeforces题解 dp 前缀和 题目描述 Time limit 2000 ms Memory ...

  7. [Codeforces 553E]Kyoya and Train(期望DP+Floyd+分治FFT)

    [Codeforces 553E]Kyoya and Train(期望DP+Floyd+分治FFT) 题面 给出一个\(n\)个点\(m\)条边的有向图(可能有环),走每条边需要支付一个价格\(c_i ...

  8. Codeforces 455B A Lot of Games:博弈dp【多局游戏】

    题目链接:http://codeforces.com/problemset/problem/455/B 题意: 给你n个字符串,然后进行k局游戏. 每局游戏开始有一个空串,然后双方轮流给这个串的末尾添 ...

  9. Codeforces 768 E. Game of Stones 博弈DP

    E. Game of Stones   Sam has been teaching Jon the Game of Stones to sharpen his mind and help him de ...

随机推荐

  1. 金错刀对话口袋购物王珂:找到痛点,确认卖点,制造爆点! - 资讯 - i黑马网

    金错刀对话口袋购物王珂:找到痛点,确认卖点,制造爆点! - 资讯 - i黑马网 金错刀对话口袋购物王珂:找到痛点,确认卖点,制造爆点!

  2. ArcGIS加载高德、OSM和谷歌等地图

    1. 引言 网络地图对于我们来说已经不是什么新鲜事了,上面有各大互联网公司收集的海量的地理空间数据.一般网络地图的地图是以切片形式存在的,因此,本文重点讲述如何将这些网络切片地图加载并显示再ArcGI ...

  3. 从此走上一条iOS程序猿不归路。。。

    新的城市,新的生活!前不久刚刚结束了苦逼的面试找工作之旅,期间也小有收货,如今正处年底工作闲暇之余,将前一阵子陆陆续续的总结整理了一下,本人菜鸟程序猿一只,水平有限,本文总结的知识不算深入,比较浅显, ...

  4. 【实验 1-2】编写一个简单的 UDP 服务器和 UDPP 客户端程序。程序均为控制台程序窗口。

    1.服务器 #include<winsock2.h> //包含头文件#include<stdio.h>#include<windows.h>#pragma comm ...

  5. android View各属性详解

    一.有8个直接子类:AnalogClock, ImageView, KeyboardView, ProgressBar, SurfaceView, TextView, ViewGroup, ViewS ...

  6. 将vim改造成C/C++开发环境(IDE) 2011

        [参考资料]吴垠的“手把手教你把Vim改装成一个IDE编程环境”在Fedora下成功将Vim打造成适用于C/C++的IDE用Vim搭建C/C++开发环境 Ubuntu下vim+ctags的配置 ...

  7. Android(java)学习笔记261:JNI之编写jni程序适配所有处理器型号

    1. 还是以"02_两个数相加"为例,你会发现这个jni程序只能在ARM处理器下运行,如下:  如果我们让上面的程序运行在x86模拟器上,处理平台不对应,报如下错误: 03-29 ...

  8. CSharp命名风格

    1.大小写约定 为了区分一个标识符中的多个单词,把标识符中的每个单词的首字母大写.不要用下划线来区分单词,或者在标识符中任何地方使用下划线,有两种方式适合大写标识符的字母: PascalCasing( ...

  9. css属性之vertical-align详解

    inline-block 该值会让元素生成一个内联级块容器(inline-level block container).一个inline-block的内部会被格式化成一个块盒,而该元素本身会被格式化成 ...

  10. JavaScript: Class.method vs Class.prototype.method

    在stack overflow中看到一个人回答,如下   // constructor function function MyClass () { var privateVariable; // p ...