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. 观【史上最牛linux视频教程】整理笔记,持续更新……

    //文件处理命令 命令格式:命令 [-参数] [参数] 例:ls -la /etc -a等于--all //目录处理命令:ls 英文原意:list 所在路径:/bin/ls 语法:ls 选项[-ald ...

  2. css3太极图效果+自动旋转

    主要使用border-radius属性实现圆,半圆,定位坐标覆盖部分模块. 半圆: width: 50%; height: 100%; border-radius:100% 0 0 100% /50% ...

  3. poj 1818 ATP

    ATP 题意:足球锦标赛使用二分的策略,每次淘汰剩下人的一半,并且数据表明:排名相差k(include)之内的运动员,胜负难料,否则排名前的必定战胜排名后的:问给定n(n = 2x, x∈N, n & ...

  4. mvc razor页面的邮箱校验

    由于@符号是razor中的关键字,而邮箱校验的正则表达式中需要使用@符号,所以在cshtml页面的代码中直接写js代码进行邮箱校验会报错. 解决方案: 将邮箱校验写在js文件中,在cshtml文件中引 ...

  5. JS & DOM 对象

    22:36 2013/6/4 详情参照W3C文档标准 Browser 对象(顶层对象) DOM Window DOM Navigator DOM Screen DOM History DOM Loca ...

  6. 开发工具IDEA的使用

    一. 先送上IDEA的下载链接 这是我个人的百度云链接,无毒无公害请放心下载~ 链接:http://pan.baidu.com/s/1kUMbatT 密码:i233 巧妇难为无米之炊,如果还没有下载安 ...

  7. python mongodb 读写CSV文件

    # -*- coding: utf-8 -*-import osimport csvimport pymongofrom pymongo import MongoClient #建立连接client ...

  8. bzoj 3672: [Noi2014]购票 树链剖分+维护凸包

    3672: [Noi2014]购票 Time Limit: 30 Sec  Memory Limit: 512 MBSubmit: 480  Solved: 212[Submit][Status][D ...

  9. 【win8技巧】win8快速切换后台应用

    今天闲着没事来介绍下win8的使用技巧,不得不说win8把PC带入了Pad时代. 第一招:Win + Tab 在屏幕的最左边就会出现我们想要的后台应用,类似安卓的长按Home的最近任务. 第二招:Al ...

  10. linux zip 命令详解

    功能说明:压缩文件. 语 法:zip [-AcdDfFghjJKlLmoqrSTuvVwXyz$][-b <工作目录>][-ll][-n <字尾字符串>][-t <日期时 ...