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. 07_XPath_01_入门

    [工程截图] [person.xml] <?xml version="1.0" encoding="UTF-8"?> <students> ...

  2. tomcat服务器启动错误

    有的时候,启动tomcat,显示的他已经启动了,但是就是没有加载任何工程,最后页面报404错误. 这时候,可以试着把服务器Clean一下

  3. c#编写简单计算器

    刚接触c#,依照惯例,写个简单的计算器,只写了加法,乘法,其他的类似,编辑器用的vs2008 首先打开vs ,新建c#的Windows窗体应用程序,接下来的项目的名称是WindowsFormsAppl ...

  4. 省选训练赛第4场D题(多米诺骨牌)

    题目来自FZU2163 多米诺骨牌 Time Limit: 1000 mSec    Memory Limit : 32768 KB  Problem Description Vasya很喜欢排多米诺 ...

  5. PHP中使用curlL实现GET和POST请求的方法

    基本结构 (1)初始化 curl_init() (2)设置变量 curl_setopt() .最为重要,一切玄妙均在此.有一长串cURL参数可供设置,它们能指定URL请求的各个细节.要一次性全部看完并 ...

  6. mysql---多表关联

    首先要介绍一下集合的概念:集合具有无序性.唯一性. 无序性:指集合内部元素没有相对顺序的概念,对于两个集合而言,只要元素值和元素个数相同则两个集合相等. 唯一性:指集合内部元素不存在值相等的元素. 上 ...

  7. Aspose.Words 总结

    生成答题卡 try { string tempPath = @"D:\moban\ttt.doc"; //Open document and create Documentbuil ...

  8. 如何更改Chrome默认的搜索引擎

    1 打开Chrome浏览器之后,点击窗口右上角的图标,在弹出的菜单中点击设置,如图所示: 2  在打开的窗口中,点击管理搜索引擎,如下图所示: 3 在弹出的窗口中,找到百度的搜索引擎或者bing的搜索 ...

  9. putty实现自动登录的方法(ssh和ssh2)

    介绍putty实现自动登录的方法.   1.登录主机并输入ssh-keygen -t rsa  提示Enter file in which to save the key (/root/.ssh/id ...

  10. Python的传值和传址与copy和deepcopy

    1.传值和传址 传值就是传入一个参数的值,传址就是传入一个参数的地址,也就是内存的地址(相当于指针).他们的区别是如果函数里面对传入的参数重新赋值,函数外的全局变量是否相应改变,用传值传入的参数是不会 ...