hdu 6105 Gameia(树形DP)
来源:互联网 发布:淘宝号出租平台 编辑:程序博客网 时间:2024/05/16 01:43
Gameia
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 263 Accepted Submission(s): 88
Problem Description
Alice and Bob are playing a game called 'Gameia ? Gameia !'. The game goes like this :
0. There is a tree with all node unpainted initial.
1. Because Bob is the VIP player, so Bob has K chances to make a small change on the tree any time during the game if he wants, whether before or after Alice's action. These chances can be used together or separate, changes will happen in a flash. each change is defined as cut an edge on the tree.
2. Then the game starts, Alice and Bob take turns to paint an unpainted node, Alice go first, and then Bob.
3. In Alice's move, she can paint an unpainted node into white color.
4. In Bob's move, he can paint an unpainted node into black color, and what's more, all the other nodes which connects with the node directly will be painted or repainted into black color too, even if they are white color before.
5. When anybody can't make a move, the game stop, with all nodes painted of course. If they can find a node with white color, Alice win the game, otherwise Bob.
Given the tree initial, who will win the game if both players play optimally?
0. There is a tree with all node unpainted initial.
1. Because Bob is the VIP player, so Bob has K chances to make a small change on the tree any time during the game if he wants, whether before or after Alice's action. These chances can be used together or separate, changes will happen in a flash. each change is defined as cut an edge on the tree.
2. Then the game starts, Alice and Bob take turns to paint an unpainted node, Alice go first, and then Bob.
3. In Alice's move, she can paint an unpainted node into white color.
4. In Bob's move, he can paint an unpainted node into black color, and what's more, all the other nodes which connects with the node directly will be painted or repainted into black color too, even if they are white color before.
5. When anybody can't make a move, the game stop, with all nodes painted of course. If they can find a node with white color, Alice win the game, otherwise Bob.
Given the tree initial, who will win the game if both players play optimally?
Input
The first line of the input gives the number of test cases T; T test cases follow.
Each case begins with one line with two integers N and K : the size of the tree and the max small changes that Bob can make.
The next line gives the information of the tree, nodes are marked from 1 to N, node 1 is the root, so the line contains N-1 numbers, the i-th of them give the farther node of the node i+1.
Limits
T≤100
1≤N≤500
0≤K≤500
1≤Pi≤i
Each case begins with one line with two integers N and K : the size of the tree and the max small changes that Bob can make.
The next line gives the information of the tree, nodes are marked from 1 to N, node 1 is the root, so the line contains N-1 numbers, the i-th of them give the farther node of the node i+1.
Limits
Output
For each test case output one line denotes the answer.
If Alice can win, output "Alice" , otherwise "Bob".
If Alice can win, output "Alice" , otherwise "Bob".
Sample Input
22 113 11 2
Sample Output
BobAlice
题解:http://bestcoder.hdu.edu.cn/blog/
a[u]=0,表示这个点已经合法,a[u]=1,表示这个点的子节点合法 当前点还在分割 ,a[u]=2表示当前点不合法;
主要就是节点的状态需要考虑清楚
#include<cstdio>#include<cstdlib>#include<cstring>#include<iostream>#include<cmath>#include<string>#include <bits/stdc++.h>using namespace std;const int N =100000+10;vector<int>p[N];int a[N];void dfs(int u,int fa){ int cnt=0; if(p[u].size()==0) { a[u]=1; return ; } for(int i=0;i<p[u].size();i++) { int v=p[u][i]; dfs(v,u); if(a[v]==1) cnt++; if(a[v]==2) {a[u]=2; return ;} } if(cnt>1) a[u]=2; else if(cnt==1) a[u]=0; else if(cnt==0) a[u]=1; return ;}int main(){ int t; scanf("%d", &t); while(t--) { int n, k; scanf("%d %d", &n, &k); for(int i=0;i<=n;i++) p[i].clear(); for(int i=2;i<=n;i++) { int x; scanf("%d", &x); p[x].push_back(i); } a[1]=2; dfs(1,-1); if(a[1]==0&&(n-2)/2<=k) puts("Bob"); else puts("Alice"); } return 0;}
阅读全文
0 0
- hdu 6105 Gameia(树形DP)
- HDU 6105 Gameia(博弈论+树形DP)
- hdu 6105 Gameia
- HDU 6105 Gameia
- HDU 6105 Gameia
- HDU-6105 Gameia
- HDU 6105 Gameia
- Gameia(HDU 6105)
- Gameia HDU 6105
- hdu 6105 Gameia
- hdu--6105--Gameia
- HDU 6105-Gameia
- HDU 6105 Gameia
- HDU 6105 Gameia 博弈
- HDU 6105 Gameia [想法题]
- HDU 6105 Gameia【思维+博弈】
- hdu 6105 Gameia 思维+策略
- HDU 6105 Gameia(思维博弈)
- 文章网址记载
- JAVA总结(三):sun.jnu.encoding与file.encoding的区别
- 洛谷 入门综合练习2
- 权限管理设计
- 利用JScript实现简单的地址选择
- hdu 6105 Gameia(树形DP)
- React Native编辑器Atom+Nuclide插件的配置和安装及编译项目
- 基本的 HTML 标签
- (吴恩达笔记 1-2)——逻辑回归
- ares 使用所需环境
- PHP对接APP的接口类,可返回json数据,xml数据
- Excel向程序发送命令时出现问题
- myeclipse中的server出现异常,
- 2017暑假训练第十天