POJ1155TELE[树形背包]
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 4957 | Accepted: 2726 |
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
//
// main.cpp
// hdu4003
//
// Created by Candy on 9/23/16.
// Copyright ? 2016 Candy. All rights reserved.
// #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int N=3e3+,INF=1e9;
int read(){
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-; c=getchar();}
while(c>=''&&c<=''){x=x*+c-''; c=getchar();}
return x*f;
}
struct edge{
int v,w,ne;
}e[N<<];
int h[N],cnt=;
void ins(int u,int v,int w){
cnt++;
e[cnt].v=v;e[cnt].w=w;e[cnt].ne=h[u];h[u]=cnt;
cnt++;
e[cnt].v=u;e[cnt].w=w;e[cnt].ne=h[v];h[v]=cnt;
}
int n,m,k,v,w,val[N],son[N];
int f[N][N];
void dp(int u,int fa){
for(int i=;i<=n;i++) f[u][i]=-INF;
if(u>=n-m+){f[u][]=val[u];son[u]=;return;} for(int i=h[u];i;i=e[i].ne){
int v=e[i].v,w=e[i].w;
if(v==fa) return;
dp(v,u); son[u]+=son[v];
for(int j=son[u];j>=;j--)
for(int k=;k<=son[v];k++){
f[u][j]=max(f[u][j],f[u][j-k]+f[v][k]-w);
}
}
}
int main(int argc, const char * argv[]) {
n=read();m=read();
for(int i=;i<=n-m;i++){
k=read();
while(k--){v=read();w=read();ins(i,v,w);}
}
for(int i=n-m+;i<=n;i++) val[i]=read();
dp(,);
for(int i=n;i>=;i--) if(f[][i]>=){printf("%d",i);break;}
}
POJ1155TELE[树形背包]的更多相关文章
- poj2486Apple Tree[树形背包!!!]
Apple Tree Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9989 Accepted: 3324 Descri ...
- cdoj 1136 邱老师玩游戏 树形背包
邱老师玩游戏 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/show/1136 Desc ...
- HDU 1011 树形背包(DP) Starship Troopers
题目链接: HDU 1011 树形背包(DP) Starship Troopers 题意: 地图中有一些房间, 每个房间有一定的bugs和得到brains的可能性值, 一个人带领m支军队从入口(房 ...
- poj 1155 TELE (树形背包dp)
本文出自 http://blog.csdn.net/shuangde800 题目链接: poj-1155 题意 某收费有线电视网计划转播一场重要的足球比赛.他们的转播网和用户终端构成一棵树状结构, ...
- bzoj 4813: [Cqoi2017]小Q的棋盘 [树形背包dp]
4813: [Cqoi2017]小Q的棋盘 题意: 某poj弱化版?树形背包 据说还可以贪心... #include <iostream> #include <cstdio> ...
- [HAOI2015]树上染色(树形背包)
有一棵点数为 N 的树,树边有边权.给你一个在 0~ N 之内的正整数 K ,你要在这棵树中选择 K个点,将其染成黑色,并将其他 的N-K个点染成白色 . 将所有点染色后,你会获得黑点两两之间的距离加 ...
- Luogu 1273 有线电视网 - 树形背包
Description 树形背包, 遍历到一个节点, 枚举它的每个子节点要选择多少个用户进行转移. Code #include<cstring> #include<cstdio> ...
- BZOJ2427: [HAOI2010]软件安装 tarjan+树形背包
分析: 一开始我以为是裸的树形背包...之后被告知这东西...可能有环...什么!有环! 有环就搞掉就就可以了...tarjan缩点...建图记得建立从i到d[i]之后跑tarjan,因为这样才能判断 ...
- [Jsoi2016]最佳团体 BZOJ4753 01分数规划+树形背包/dfs序
分析: 化简一下我们可以发现,suma*ans=sumb,那么我们考虑二分ans,之后做树形背包上做剪枝. 时间复杂度证明,By GXZlegend O(nklogans) 附上代码: #includ ...
随机推荐
- 关于EJB的理解
这一段时间一直在北京面试,很多都有关EJB的相关问题,于是上网查了各种资料.所以,EJB到底是什么? 简而言之:EJB就是将已编写的软件中的业务类.不放到客户端软件中,而将其打包放入服务器中.以C/S ...
- 第一次写jquery插件,来个countdown计时器吧
之前同学做个购物商城秒杀活动需要计时器的功能,在用jquery提供的countdown插件时,一直报错,貌似还需要依赖除jquery之外的其他插件,搞了半天也没搞成功,就叫我帮忙写个.然而我并没有写过 ...
- ArcGIS中国工具2.2正式发布
ArcGIS中国工具2.2新功能 1. 2.0全面支持ArcGIS10.3 2. 全面修改成插件,原来部分是独立运行的EXE 3. 可以制作倾斜的矩形图框 4. 修改宗地(地块)左上角为第一个点,填写 ...
- linux 压缩命令详解
原文地址:http://www.2cto.com/os/201112/114982.html 编写shell脚本的时候经常需要解压缩到指定的文件夹,tar命令是最常用的 参考一下说明,其中注意-C的用 ...
- Android存储访问及目录
Android存储访问及目录 Android的外部存储 Android支持外部存储(case-insensitive filesystem with immutable POSIX permissio ...
- umeng 渠道统计 android
1.配置AndroidManifest.xml,添加权限 <uses-permission android:name="android.permission.ACCESS_NETWOR ...
- Android Studio git 版本回退到最新的版本
1.场景 1.1 最新三次的提交 分别是:定义了一个变量k = 10 . 定义了一个变量 j = 6 . 定义了一个变量 i = 5 ; 本地仓库 和 远程仓库保持一致 1.2 我添加了一行代码 ...
- 【代码笔记】iOS-显示图片的各种方式
代码: - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. UI ...
- VisualSVN Server的配置和使用方法 图文
转载 http://www.jb51.net/article/17365.htm VisualSVN Server是免费的,而VisualSVN是收费的.VisualSVN是SVN的客户端,和Visu ...
- MyEclipse、Eclipse优化设置
第一步: 取消自动validation validation有一堆,什么xml.jsp.jsf.js等等,我们没有必要全部都去自动校验一下,只是需要的时候才会手工校验一下! 取消方法: windows ...