TELE
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 3787   Accepted: 2007

Description

A TV-network plans to broadcast an important football match. Their network of transmitters and users can be represented as a tree. The root of the tree is a transmitter that emits the football match, the leaves of the tree are the potential users and other vertices in the tree are relays (transmitters).  The price of transmission of a signal from one transmitter to another or to the user is given. A price of the entire broadcast is the sum of prices of all individual signal transmissions.  Every user is ready to pay a certain amount of money to watch the match and the TV-network then decides whether or not to provide the user with the signal.  Write a program that will find the maximal number of users able to watch the match so that the TV-network's doesn't lose money from broadcasting the match.

Input

The first line of the input file contains two integers N and M, 2 <= N <= 3000, 1 <= M <= N-1, the number of vertices in the tree and the number of potential users.  The root of the tree is marked with the number 1, while other transmitters are numbered 2 to N-M and potential users are numbered N-M+1 to N.  The following N-M lines contain data about the transmitters in the following form:  K A1 C1 A2 C2 ... AK CK  Means that a transmitter transmits the signal to K transmitters or users, every one of them described by the pair of numbers A and C, the transmitter or user's number and the cost of transmitting the signal to them.  The last line contains the data about users, containing M integers representing respectively the price every one of them is willing to pay to watch the match.

Output

The first and the only line of the output file should contain the maximal number of users described in the above text.

Sample Input

9 6
3 2 2 3 2 9 3
2 4 2 5 2
3 6 2 7 2 8 2
4 3 3 3 1 1

Sample Output

5

Source

Croatia OI 2002 Final Exam - Second Day
 
树形背包、注意理解、上代码 - -
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
#define INF 0x7ffffff
#define ll long long
#define N 3010 struct Edge
{
int to,next,len;
}edge[N];
int head[N],tot; int n,m;
int val[N];
int num[N];
int dp[N][N]; /* dp[i][j]表示在节点i为根节点的子树,有j个叶子节点时的最大利润 */
/* 状态转移方程: dp[i][j] = max(dp[i][j], dp[i][k]+dp[son][j-k]-w[i][son]); */
void init()
{
tot=;
memset(head,-,sizeof(head));
for(int i=;i<=n;i++)
{
for(int j=;j<=m;j++)
{
dp[i][j]=-INF;
}
}
}
void add(int x,int y,int z)
{
edge[tot].to=y;
edge[tot].len=z;
edge[tot].next=head[x];
head[x]=tot++;
}
void dfs(int u)
{
if(head[u]==-)
{
num[u]=;
dp[u][]=val[u];
}
for(int i=head[u];i!=-;i=edge[i].next)
{
int v=edge[i].to;
int w=edge[i].len;
dfs(v);
num[u]+=num[v];
for(int j=num[u];j>=;j--)
{
for(int k=;k<=j;k++)
{
dp[u][j]=max(dp[u][j],dp[u][j-k]+dp[v][k]-w);
}
}
}
}
int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
init();
for(int i=;i<=n-m;i++)
{
int a,b,c;
scanf("%d",&c);
for(int j=;j<c;j++)
{
scanf("%d%d",&a,&b);
add(i,a,b); }
}
for(i=n-m+;i<=n;i++)
{
scanf("%d",&val[i]);
}
dfs(); for(int i=m;i>=;i--)
{
if(dp[][i]>=)
{
printf("%d\n",i);
break;
}
}
}
return ;
}

[POJ 1155] TELE的更多相关文章

  1. [POJ 1155] TELE (树形dp)

    题目链接:http://poj.org/problem?id=1155 题目大意:电视台要广播电视节目,要经过中转机构,到观众.从电视台到中转商到观众是一个树形结构,经过一条边需要支付成本.现在给你每 ...

  2. poj 1155 TELE(树形DP)

    TELE Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4863   Accepted: 2673 Description ...

  3. POJ 1155 TELE 背包型树形DP 经典题

    由电视台,中转站,和用户的电视组成的体系刚好是一棵树 n个节点,编号分别为1~n,1是电视台中心,2~n-m是中转站,n-m+1~n是用户,1为root 现在节点1准备转播一场比赛,已知从一个节点传送 ...

  4. POJ 1155 - TELE 树型DP(泛化背包转移)..

    dp[x][y]代表以x为根的子树..连接了y个终端用户(叶子)..所能获得的最大收益... dp[x][ ]可以看成当根为x时..有个背包空间为0~m...每个空间上记录了到到达这个空间的最大收益. ...

  5. poj 1155 TELE (树形背包dp)

    本文出自   http://blog.csdn.net/shuangde800 题目链接: poj-1155 题意 某收费有线电视网计划转播一场重要的足球比赛.他们的转播网和用户终端构成一棵树状结构, ...

  6. POJ 1155 TELE [树状DP]

    题意:略. 思路:用dp[i][k]来表示结点i给k个用户提供节目时的最大盈利(可能为负). 则递推方程为: dp[i][j] = max(dp[i][j], dp[i][m] + dp[v][j-m ...

  7. POJ 1155 TELE (树形DP,树形背包)

    题意:给定一棵树,n个节点,其中有m个叶子表示的是用户,其他点表示中转器, 每条边都有权值,每个用户i愿意给的钱w[i],问如果在不亏钱的情况下能为多少用户转播足球比赛? 思路: 其实就是要选出部分叶 ...

  8. POJ 1155 树形背包(DP) TELE

    题目链接:  POJ 1155 TELE 分析:  用dp[i][j]表示在结点i下最j个用户公司的收益, 做为背包处理.        dp[cnt][i+j] = max( dp[cnt][i+j ...

  9. poj 1155 输入输出问题

    http://acm.hust.edu.cn/vjudge/problem/16417 重做了一遍poj 1155 题目大意:给定一棵树,1为根结点表示电视台,有m个叶子节点表示客户,有n-m-1个中 ...

随机推荐

  1. libjingle线程机制

    libjingle包装了所有的线程,包括signaling thread,worker thread, 和其它任何线程,用talk_base::Thread来包装.所有的 Thread对象由Threa ...

  2. FlatBuffers

    1 What is FlatBuffers. FlatBuffers is a serialization library for games and other memory constrained ...

  3. 把URL传递参数转变成自定义实体方法

    先定义下要获取的实体: public class InputClass { public long Id { get; set; } public int Status { get; set; } p ...

  4. Linux下的I/O复用与epoll详解

    前言 I/O多路复用有很多种实现.在linux上,2.4内核前主要是select和poll,自Linux 2.6内核正式引入epoll以来,epoll已经成为了目前实现高性能网络服务器的必备技术.尽管 ...

  5. java感触一则

    看到开源中国上边有那么多关于java的开源项目,从数据库到3D游戏再到IDE工具,甚至有iQQ,形形种种都是一些比较成熟的,工程很大的项目.才意识到Java是如此的强大和流行. 这么多开源的代码我不可 ...

  6. java basic

    //java 声明常量 //final 数据类型 常量名=值; //as: final float PI=3.14f;/ PI=3.14002F //默认浮点为 double //break:跳出多重 ...

  7. PHP字符

    匹配查找 strstr strpos 通常用在表单验证里面可以用到 substr 正值表达式匹配 preg_mathc(), preg)mathc_all() , preg_grep() 编码格式的转 ...

  8. JAVA学习资料整理

    今天偶然间发现之前一个群里发过的一篇关于JAVA学习资料的东西.本着服务大众的精神,搬来了博客园: <JAVA编程思想>第四版(英文原版) 下载地址:http://115.com/file ...

  9. LED字符设备驱动实例及测试代码

    驱动代码如下: #include <linux/kernel.h>//内核头文件 #include <linux/init.h>//__init等 #include <l ...

  10. hdu 1251 统计难题 trie入门

    统计难题 Problem Description Ignatius最近遇到一个难题,老师交给他很多单词(只有小写字母组成,不会有重复的单词出现),现在老师要他统计出以某个字符串为前缀的单词数量(单词本 ...