1694 An Old Stone Game
来源:互联网 发布:移民美国知乎 编辑:程序博客网 时间:2024/05/21 06:48
An Old Stone Game
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 2310 Accepted: 1014
Description
There is an old stone game, played on an arbitrary general tree T. The goal is to put one stone on the root of T observing the following rules:
The player wins the game if by following the above rules, he succeeds to put one stone on the root of the tree.
You are to write a program to determine the least number of stones to be picked at the beginning of the game (K), so that the player can win the game on the given input tree.
- At the beginning of the game, the player picks K stones and puts them all in one bucket.
- At each step of the game, the player can pick one stone from the bucket and put it on any empty leaf.
- When all of the r immediate children of a node p each has one stone, the player may remove all of these r stones, and put one of the stones on p. The other r - 1 stones are put back into the bucket, and can be used in the later steps of the game.
The player wins the game if by following the above rules, he succeeds to put one stone on the root of the tree.
You are to write a program to determine the least number of stones to be picked at the beginning of the game (K), so that the player can win the game on the given input tree.
Input
The input describes several trees. The first line of this file is M, the number of trees (1 <= M <= 10). Description of these M trees comes next in the file. Each tree has N < 200 nodes, labeled 1, 2, ... N, and each node can have any possible number of children. Root has label 1. Description of each tree starts with N in a separate line. The following N lines describe the children of all nodes in order of their labels. Each line starts with a number p (1 <= p <= N, the label of one of the nodes), r the number of the immediate children of p, and then the labels of these r children.
Output
One line for each input tree showing the minimum number of stones to be picked in step 1 above, in order to win the game on that input tree.
Sample Input
271 2 2 32 2 5 43 2 6 74 05 06 07 0121 3 2 3 42 03 2 5 64 3 7 8 95 3 10 11 126 07 08 09 010 011 012 0
Sample Output
34
- 1694 An Old Stone Game
- POJ 1694 An Old Stone Game
- POJ 1694 An Old Stone Game
- POJ--1694--An Old Stone Game
- poj 1694 An old stone game
- 北大oj 1694 An Old Stone Game
- POJ 1694 An Old Stone Game 笔记
- POJ1694 An Old Stone Game
- POJ 1694 An Old Stone Game【递归+排序】
- poj 1694 An Old Stone Game 树形dp
- POJ1694 An Old Stone Game (树,排序) .
- ZOJ1427 POJ1694 An Old Stone Game
- An old Stone Game ~~GarsiaWachs算法
- POJ 1738 An old Stone Game 笔记
- POJ1694,An Old Stone Game,读懂题目+dfs
- An Old Stone Game(poj1694模拟与排序)
- poj1738 An old Stone Game 石子合并(归并) GarsiaWachs算法
- poj1738 An old Stone Game 石子合并(归并) GarsiaWachs算法
- c#.net同步异步SOCKET通讯和多线程总结
- oracle的分析函数over 及开窗函数
- 控规入库标准
- 1118 Lining Up
- 通过虚拟机防火墙来上网的配置
- 1694 An Old Stone Game
- QT中使用THUNK技术实现回调问题
- Java中JTable的用法
- 1111 Image Perimeters
- ACCESS数据库后台sql语句执行导webshell
- 从零开始
- Android Activity生命周期具体内容概述
- 开始玩博客了
- 《汇编语言程序设计》