//poj 1694
//sep9
#include <iostream>
#include <algorithm>
using namespace std;
const int maxN=256;
int n;
int tree[maxN][maxN];
int ans[maxN];
int cmp(int a,int b)
{
return a>b;
}
int dfs(int u)
{
int tmp[maxN],t=0;
if(tree[u][0]==0)
return ans[u]=1;
for(int i=1;i<=tree[u][0];++i){
dfs(tree[u][i]);
tmp[t++]=ans[tree[u][i]];
}
sort(tmp,tmp+t,cmp);
int maxx=-1;
for(int i=0;i<t;++i)
maxx=max(maxx,tmp[i]+i);
return ans[u]=maxx;
} int main()
{
int cases;
scanf("%d",&cases);
while(cases--){
scanf("%d",&n);
for(int i=1;i<=n;++i)
tree[i][0]=0;
for(int i=0;i<n;++i){
int u,x;
scanf("%d%d",&u,&x);
while(x--){
int v;
scanf("%d",&v);
tree[u][++tree[u][0]]=v;
}
}
printf("%d\n",dfs(1));
}
}

poj 1694 An Old Stone Game 树形dp的更多相关文章

  1. POJ 2342 &&HDU 1520 Anniversary party 树形DP 水题

    一个公司的职员是分级制度的,所有员工刚好是一个树形结构,现在公司要举办一个聚会,邀请部分职员来参加. 要求: 1.为了聚会有趣,若邀请了一个职员,则该职员的直接上级(即父节点)和直接下级(即儿子节点) ...

  2. POJ 3162 bit区间查询最值+树形DP

    POJ 3162 『题目链接』POJ 3162 『题目类型』bit区间查询最值+树形DP ✡Problem: 一棵n个节点的树.wc爱跑步,跑n天,第i天从第i个节点开始跑步,每次跑到距第i个节点最远 ...

  3. POJ 1694 An Old Stone Game【递归+排序】

    链接: http://poj.org/problem?id=1694 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=27454#probl ...

  4. POJ - 2057 The Lost House(树形DP+贪心)

    https://vjudge.net/problem/POJ-2057 题意 有一只蜗牛爬上某个树枝末睡着之后从树上掉下来,发现后面的"房子"却丢在了树上面,.现在这只蜗牛要求寻找 ...

  5. POJ题目1947 Rebuilding Roads(树形dp)

    Rebuilding Roads Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 9957   Accepted: 4537 ...

  6. POJ 1694 An Old Stone Game

    题目: Description There is an old stone game, played on an arbitrary general tree T. The goal is to pu ...

  7. poj 2342 【Anniversary party】树形dp

    题目传送门//res tp poj 题意 给出一棵有权树,求一个节点集的权值和,满足集合内的任意两点不存在边 分析 每个点有选中与不选中两种状态,对于第\(i\)个点,记选中为\(sel_i\),不选 ...

  8. 【Poj】 p2342 Anniversary party(树形DP第一道)

    Anniversary party Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5523   Accepted: 3169 ...

  9. POJ 1849 Two(树的直径--树形DP)(好题)

    大致题意:在某个点派出两个点去遍历全部的边,花费为边的权值,求最少的花费 思路:这题关键好在这个模型和最长路模型之间的转换.能够转换得到,全部边遍历了两遍的总花费减去最长路的花费就是本题的答案,要思考 ...

随机推荐

  1. 网络设备之ospf2

    OSPF(Open Shortest Pass First,开放最短路径优先协议),是一个最常用的内部网管协议,是一个链路状态协议. OSPF的特点 OSPF是一种无类路由协议,支持VLSM可变长子网 ...

  2. centos7.2 安装nginx

    一.首先检查gcc编译器安装了没 二 首先安装必要的库(nginx 中gzip模块需要 zlib 库,rewrite模块需要 pcre 库,ssl 功能需要openssl库),检查一下是否已经安装了( ...

  3. python爬虫基础05-beautifulsoup

    HTML解析库BeautifulSoup4 本文链接:https://www.jianshu.com/p/e9255c446a77 BeautifulSoup 是一个可以从HTML或XML文件中提取数 ...

  4. Python的第二堂课(2)

    一.初探python print('Hello,靓仔!') 不得不说,这句话还是so real的(逃 二.Python中的变量 1.什么是变量?(what) 量:记录某种现实世界中事物的某种状态: 变 ...

  5. PAT Basic 1054

    1054 求平均值 本题的基本要求非常简单:给定 N 个实数,计算它们的平均值.但复杂的是有些输入数据可能是非法的.一个“合法”的输入是 [−1000,1000] 区间内的实数,并且最多精确到小数点后 ...

  6. jq:mouseover和mouseout多次触发解决办法

    区别: mouseover与mouseenter 不论鼠标指针穿过被选元素或其子元素,都会触发 mouseover 事件. 只有在鼠标指针穿过被选元素时,才会触发 mouseenter 事件. mou ...

  7. django基础(web框架,http协议,django安装)

    学习Django之前我们先来看什么是OSI七层模型: 应用层 表示层       应用层(五层模型中把这三层合成一个应用层) http协议 会话层 传输层                  提供端口对 ...

  8. Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. k is a positive integer and is less than or equal to the length of the linked list. If the number of

    class Solution { public: ListNode *reverseKGroup(ListNode *head, int k) { if (!head || !(head->ne ...

  9. A. Nearest Common Ancestors

    A. Nearest Common Ancestors Time Limit: 1000ms Case Time Limit: 1000ms Memory Limit: 10000KB   64-bi ...

  10. MySQL容量规划之tcpcopy应用之道

    官方文档:https://github.com/session-replay-tools/mysql-replay-module tcpcopy可以将正式环境上来自客户端的请求复制一份到测试端并复现, ...