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. Struts2文件上传功能浅析

    本文将以图片上传为例,解析Struts2文件上传的主要过程实例的功能:1.在jsp页面选择要上传的图片,                 2.为待上传的图片取名,以便于查找               ...

  2. QML定时器

    QML中的定时器能够周期性的触发一个事件,其使用非常简单.方便.这里给出一个示例: import QtQuick 2.4 import QtQuick.Controls 1.3 import QtQu ...

  3. Python3 多进程和多线程

    Unix/Linux操作系统提供了一个fork()系统调用,它非常特殊.普通的函数调用,调用一次,返回一次,但是fork()调用一次,返回两次,因为操作系统自动把当前进程(称为父进程)复制了一份(称为 ...

  4. Leetcode按Tag刷题

    按照Leetcode的Tag来刷题,从easy到hard刷题 关于如何让Leetcode按难易程度排序,可按以下步骤: 1. 进入Leetcode后,点击code 2.点击code后,可查看所有题目, ...

  5. 微调Win8.1这台电脑

    从前有个笑话:一位朋友在办公室受到领导教育:“我说小王同志啊,虽然这电脑是你打了报告组织上买给你用的,可是你也不好这么狂妄嘛...”可怜的他只好把图标的名字改为“大家的电脑”. 想必大家已经知道这个笑 ...

  6. PHP初学留神(三)

    星期一进行面试结束后,意味着我的考研日子也结束了,以及我的2013.在好好总结之后还不能停止学习,心想着要把算法继续学下去,还有Linux.不过呢,始终都要记住尼采老师的这句当头棒喝:“不加选择的知识 ...

  7. Java集合Map接口与Map.Entry学习

    Java集合Map接口与Map.Entry学习 Map接口不是Collection接口的继承.Map接口用于维护键/值对(key/value pairs).该接口描述了从不重复的键到值的映射. (1) ...

  8. OpenFileDialog组件打开文件....待续

    1.常用属性 InitialDirectory           对话框的初始目录 this.openFileDialog1.InitialDirectory = "d:\\"; ...

  9. Unity3d Shader开发(四)UsePass ,GrabPass ,SubShader Tags

    (一)UsePass 命令 使用 来自另一个着色器的命名通道. Syntax 语法 UsePass "Shader/Name" 插入所有来自给定着色器中的给定名字的通道.Shade ...

  10. NSAssert使用摘抄

    #define NSAssert(condition, desc, ...) 只有条件condition满足,才会执行下一个语句,否则输出断言错误. 例如: NSAssert(1 != 2, @&qu ...