【树形dp】TELE
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 5376 | Accepted: 2973 |
Description
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 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
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
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
using namespace std; inline int read(){
int x=0,f=1;char c=getchar();
for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
for(;isdigit(c);c=getchar()) x=x*10+c-'0';
return x*f;
}
const int MAXN=8001;
const int INF=999999;
int N,M;
int Node[MAXN],Root[MAXN],Next[MAXN],Cost[MAXN];
int cnt;
int val[MAXN];
int tel[MAXN];
int dp[3001][3001]; void addedge(int u,int v,int w){
++cnt;
Node[cnt]=v; Cost[cnt]=w;
Next[cnt]=Root[u];
Root[u]=cnt;
return ;
}
void dfs(int x){
if(x>N-M){
tel[x]=1;
dp[x][1]=val[x];
dp[x][0]=0;
return ;
}
for(int k=Root[x];k;k=Next[k]){
int son=Node[k];
dfs(son);
}
int tmp=0;dp[x][0]=0;
for(int k=Root[x];k;k=Next[k]){
int son=Node[k];
tmp+=tel[son];
for(int t=tmp;t>=1;t--){
for(int p=1;p<=tel[son];p++){
if(p>t) break;
dp[x][t]=max(dp[x][t],dp[son][p]+dp[x][t-p]-Cost[k]);
}
}
}
tel[x]=tmp;
return ;
} int main(){
N=read(),M=read();
for(int i=0;i<=N;i++)
for(int j=0;j<=M;j++) dp[i][j]=-INF;
for(int i=1;i<=N-M;i++){
int k=read();
while(k--){
int v=read(),w=read();
addedge(i,v,w);
}
}
for(int i=1;i<=M;i++) val[i+N-M]=read();
dfs(1); int ans=M;
while(dp[1][ans]<0) ans--;
printf("%d\n",ans);
}
【树形dp】TELE的更多相关文章
- POJ 1155 TELE 背包型树形DP 经典题
由电视台,中转站,和用户的电视组成的体系刚好是一棵树 n个节点,编号分别为1~n,1是电视台中心,2~n-m是中转站,n-m+1~n是用户,1为root 现在节点1准备转播一场比赛,已知从一个节点传送 ...
- [POJ 1155] TELE (树形dp)
题目链接:http://poj.org/problem?id=1155 题目大意:电视台要广播电视节目,要经过中转机构,到观众.从电视台到中转商到观众是一个树形结构,经过一条边需要支付成本.现在给你每 ...
- 树形DP
切题ing!!!!! HDU 2196 Anniversary party 经典树形DP,以前写的太搓了,终于学会简单写法了.... #include <iostream> #inclu ...
- 【转】【DP_树形DP专辑】【9月9最新更新】【from zeroclock's blog】
树,一种十分优美的数据结构,因为它本身就具有的递归性,所以它和子树见能相互传递很多信息,还因为它作为被限制的图在上面可进行的操作更多,所以各种用于不同地方的树都出现了,二叉树.三叉树.静态搜索树.AV ...
- 【DP_树形DP专题】题单总结
转载自 http://blog.csdn.net/woshi250hua/article/details/7644959#t2 题单:http://vjudge.net/contest/123963# ...
- DP专题·四(树形dp)
1.poj 115 TELE 题意:一个树型网络上有n个结点,1~n-m为信号传送器,n-m+1~n为观众,当信号传送给观众后,观众会付费观看,每铺设一条道路需要一定费用.现在求以1为根,使得收到观众 ...
- 基础树形DP小结
HDU 4044 Geodefense http://blog.csdn.net/zmx354/article/details/25109897 树形DP暂且先告一段落了. HDU 3586 Info ...
- poj3417 LCA + 树形dp
Network Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 4478 Accepted: 1292 Descripti ...
- COGS 2532. [HZOI 2016]树之美 树形dp
可以发现这道题的数据范围有些奇怪,为毛n辣么大,而k只有10 我们从树形dp的角度来考虑这个问题. 如果我们设f[x][k]表示与x距离为k的点的数量,那么我们可以O(1)回答一个询问 可是这样的话d ...
- 【BZOJ-4726】Sabota? 树形DP
4726: [POI2017]Sabota? Time Limit: 20 Sec Memory Limit: 128 MBSec Special JudgeSubmit: 128 Solved ...
随机推荐
- js_面向对象设计和行为委托设计模式
最近换了新工作,面试过程中有多多少少的问题没有给的出答案,为自己的技术短板而促急. javascript中万物皆对象(键:值构成的一种数据),暂且不讨论这个句话的对与错,可以想象对象在javascri ...
- 【Eclipse】Eclipse中修改项目的映射名称与端口
1.正常部署(映射的名字为项目名字,端口为8080)
- 【C语言】Coursera课程《计算机程式设计》台湾大学刘邦锋——Week6 String课堂笔记
Coursera课程 <计算机程式设计>台湾大学 刘邦锋 Week6 String 6-1 Character and ASCII 字符变量的声明 char c; C语言使用一个位元组来储 ...
- python基础===装饰器@property 的扩展
以下来自Python 3.6.0 Document: class property(fget=None, fset=None, fdel=None, doc=None) Return a proper ...
- python基础===PEP网站,代码规范指南
PEP 8是最古老的PEP之一,它向Python程序员提供了代码格式设置指南.PEP 8的篇幅很长,但大都与复杂的编码结构相关. https://python.org/dev/peps/pep-000 ...
- smb windows中使用的文件共享协议(主要用于与windows互通)
主要是samba服务. SMB协议又成为CIFS(Common Internet File System)协议 samba服务功能: 1文件共享 2打印共享 3加入windows2000/2003/2 ...
- rabbitmq和ons-rocketmq使用对比
MQ,其实目的都是一样,就是应对系统的并发可以实现消峰和解耦的作用,类似于创建了一个线程异步操作,这一点可以了解一下一款优秀的并发框架(Disruptor),据说是每秒可以处理十万级数据, 目前据本人 ...
- Every Tom,Dick and Harry. 不管张三李四。
1 every adj 每个,最大的,所有的,一切的 Every other girl except me is wearing jeans. 除了我之外的每个女孩都穿着牛仔裤. I have ...
- 流程控制--while
/* while 是在有条件控制的情况下 进行的循环 */ [root@localhost test1]# vim .py //ADD #!/usr/bin/python n = while True ...
- udp调用connect有什么作用(转)
原文链接如下: http://blog.csdn.net/wannew/article/details/18218619 整理一下.1:UDP中可以使用connect系统调用 2:UDP中connec ...