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

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

/*1是广播总站 ,2到n-m是重转站,n-m+1到n是用户,给出连接两个站或用户之间的费用,以及每个用户愿意出的钱,问在电视台
不亏本的前提下,最多有多少用户可以收看到电视*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <iomanip>
#define INF 0x3f3f3f3f
#define N 3010
using namespace std;
int n,m;
struct node
{
int to,w;
node(int a,int b){to=a,w=b;};
};
vector<node >edge[N*];
int val[N];
int dp[N][N];//dp[u][j]表示以u为结点,提供给j个用户的的时候最少亏的钱
int dfs(int u,int p)//当前结点,父节点
{
dp[u][]=;
int ans=,cut=;//记录用户的人数,和v是不是用户
for(int i=;i<edge[u].size();i++)
{
int v=edge[u][i].to;//下一步
int w=edge[u][i].w;//走这一步需要的费用
if(v==p) continue;//和父节点重合的时候就跳过
int cup=dfs(v,u);//v的用户人数
if(v>=n-m+)//v是用户不是广播站
{
cup++;//u的用户总人数+1
cut=;
}
else
cut=;
ans+=cup;//u的用户人数
//cout<<"cup="<<cup<<endl;
for(int j=min(ans,m);j>=;j--)//u的用户
{
for(int k=min(cup,j);k>=;k--)//v的用户
{
dp[u][j]=min(dp[u][j],dp[u][j-k]+dp[v][k-cut]+w-val[v]);
}
} }
//cout<<"u="<<u<<" "<<"ans="<<ans<<endl;
/*dfs出每结点的儿子数没问题*/
return ans;//输出有几个用户
}
int main()
{
//freopen("in.txt","r",stdin);
while(scanf("%d%d",&n,&m)!=EOF)
{
int a,b,t;
for(int i=;i<=n;i++)
edge[i].clear();
memset(val,,sizeof val);
for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
dp[i][j]=INF;
for(int i=;i<=n-m;i++)
{
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&a,&b);
edge[i].push_back(node(a,b));
edge[a].push_back(node(i,b));
}
}//整理输入
for(int i=n-m+;i<=n;i++)
scanf("%d",&val[i]);
dfs(,-);
int cur=;
for(int i=;i<=n;i++)
{
//cout<<"dp[1][i]="<<dp[1][i]<<endl;
if(dp[][i]<=)
cur=i;
}
printf("%d\n",cur);
}
return ;
}

poj 1155 TELE(树形DP)的更多相关文章

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

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

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

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

  3. Apple Tree POJ - 2486 (树形dp)

    题目链接: D - 树形dp  POJ - 2486 题目大意:一颗树,n个点(1-n),n-1条边,每个点上有一个权值,求从1出发,走V步,最多能遍历到的权值 学习网址:https://blog.c ...

  4. Anniversary party POJ - 2342 (树形DP)

    题目链接:  POJ - 2342 题目大意:给你n个人,然后每个人的重要性,以及两个人之间的附属关系,当上属选择的时候,他的下属不能选择,只要是两个人不互相冲突即可.然后问你以最高领导为起始点的关系 ...

  5. POJ 3107.Godfather 树形dp

    Godfather Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7536   Accepted: 2659 Descrip ...

  6. POJ 3342 (树形DP)

    题意 :给出一些上下级关系,要求i和i的直接上级不能同时出现,现在选出一些人构成一个集合,问你这个集合里面的最大人数是都少,同时给出这个最大的人数的集合是否唯一. 思路:树形DP,dp[i][0],表 ...

  7. POJ 2342 (树形DP)

    Anniversary party Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3863   Accepted: 2172 ...

  8. POJ Anniversary party 树形DP

    /* 树形dp: 给一颗树,要求一组节点,节点之间没有父子关系,并且使得所有的节点的权值和最大 对于每一个节点,我们有两种状态 dp[i][0]表示不选择节点i,以节点i为根的子树所能形成的节点集所能 ...

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

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

随机推荐

  1. JVM 菜鸟进阶高手之路九(解惑)

    转载请注明原创出处,谢谢! 在第八系列最后有些疑惑的地方,后来还是在我坚持不懈不断打扰笨神,阿飞,ak大神等,终于解决了该问题.第八系列地址:http://www.cnblogs.com/lirenz ...

  2. HDU2688-Rotate

    Recently yifenfei face such a problem that give you millions of positive integers,tell how many pair ...

  3. ThinkPHP中:检查Session是否过期

    1.创建Session public function index(){ $sess_time=time(); session('name','andy'); session('time_stamp' ...

  4. (一) .net core 2.0 初体验

    1..net core 2.0环境 .net core 下载地址:https://www.microsoft.com/net/core#windowscmd 问题一:提示[Failed to load ...

  5. Python操作csv文件

    1.什么是csv文件 The so-called CSV (Comma Separated Values) format is the most common import and export fo ...

  6. 郑厂长系列故事——排兵布阵 hdu4539(状态压缩DP)

    郑厂长系列故事——排兵布阵 Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)To ...

  7. python之路第二篇(基础篇)

    入门知识: 一.关于作用域: 对于变量的作用域,执行声明并在内存中存在,该变量就可以在下面的代码中使用. if 10 == 10: name = 'allen' print name 以下结论对吗? ...

  8. RobotFramework自动化测试框架-移动手机自动化测试Click Element关键字的使用

    Click Element关键字用来模拟点击APP界面上的一个元素,该关键字接收一个参数[ locator ] ,这里的locator指的是界面元素的定位方式. 示例1:使用Click Element ...

  9. Ubuntu访问window下的磁盘分区出现“Error mounting /dev/sda5 at/media”错误的解决方法

    我装ubuntu之前,电脑上安装了windows 10,为了装ubuntu,在window 10下的磁盘工具分配了30G的磁盘空间.安装完Ubuntu之后,访问window 10的磁盘分区出现“Err ...

  10. 基于nginx的虚拟主机的配置

    安装pcre tar -xvf pcre-8.32.tar.gz cd pcre-8.32 ./configure make;make install 安装nginx 首先创建一个nginx用户,以n ...