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 ...
随机推荐
- 频率直方图(hist)
频率直方图(frequency histogram)亦称频率分布直方图.统计学中表示频率分布的图形.在直角坐标系中,用横轴表示随机变量的取值,横轴上的每个小区间对应一个组的组距,作为小矩形的底边:纵轴 ...
- Nmap源码分析(脚本引擎)
Nmap提供了强大的脚本引擎(NSE),以支持通过Lua编程来扩展Nmap的功能.目前脚本库已经包含300多个常用的Lua脚本,辅助完成Nmap的主机发现.端口扫描.服务侦测.操作系统侦测四个基本功能 ...
- Sql Server 2008 数据库附加失败提示9004错误解决办法
附加数据库 对于 服务器“WSS_Content”失败. (Microsoft.SqlServer.Smo)执行 Transact-SQL 语句或批处理时发生了异常. (Microsoft.SqlS ...
- Mac本“安全性与隐私”里没有“任何来源”选项
打开"偏号设置"----->"安全性与隐私"----->"通用",里面没有"任何来源",怎么解决? 如果需要 ...
- webView 显示一段 html 代码
1.布局文件 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:and ...
- Android四大组件之Activity一(组件的概念、Intent、监听)
前言知识补充: 什么是组件? 1.它的类必须实现特定接口或继承特定类 2.需要在配置文件中配置其全类名 3.它的对象不是通过new来创建的, 而是系统自动创建的 4.它的对象具有一定 ...
- 【代码笔记】iOS-对UIView进行截图
一,效果图. 二,工程图. 三,代码. RootViewController.m #import "RootViewController.h" @interface RootVie ...
- 自己用js写的日历(在考勤中使用,显示员工的日期的考勤情况)
1.HTML部分 <div id="AttendanceDataDetailDiv"> <div class="A_close"> &l ...
- HashSet、LinkedHashSet、TreeSet
以下内容基于jdk1.7.0_79源码: 关于HashSet.LinkedHashSet.TreeSet Set接口的实现类,最大特点是不允许出现重复元素: HashSet:基于HashMap实现,一 ...
- (ios)MPMoviePlayerController首次播放视频的时候,没有控制条
问题: 在视频播放时,现在控制条采用磨砂的效果,会遮罩部分视频 解决思路 1 播放器直接设置不带控制条,在app在 Foreground状态,默认播放器暂停,这样需要在获得Foreground事件,进 ...