日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

[POJ1155]TELE

發布時間:2025/3/14 编程问答 16 豆豆
生活随笔 收集整理的這篇文章主要介紹了 [POJ1155]TELE 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

[POJ1155]TELE

試題描述

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.

輸入

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.

輸出

The first and the only line of the output file should contain the maximal number of users described in the above text.

輸入示例

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

輸出示例

5

數據規模及約定

見“輸入”;另:過程中不會有超過 int 的值。

題解

樹形 dp(樹上背包)。

設 f(i, j) 表示子樹 i 中選擇了 j 個葉子的最大獲利(若為負則 -f(i, j) 為最小虧損)。那么答案就是最大的 j,滿足 f(i, j) 非負。

考慮子樹 u,兒子上的信息肯定是最有子結構,所以先算出所有的 f(son, j),然后分別將一個個子樹的信息加入 f(i, j)(f(u, i+j) = max{ f(u, i) + f(son, j) - dist(i, son) | j > 0 , f(u, i) + f(son, j) | j = 0 })。

可以證明總轉移數是 O(n2) 級別的,詳見這里。

#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <cctype> #include <algorithm> using namespace std;const int BufferSize = 1 << 16; char buffer[BufferSize], *Head, *Tail; inline char Getchar() {if(Head == Tail) {int l = fread(buffer, 1, BufferSize, stdin);Tail = (Head = buffer) + l;}return *Head++; } int read() {int x = 0, f = 1; char c = Getchar();while(!isdigit(c)){ if(c == '-') f = -1; c = Getchar(); }while(isdigit(c)){ x = x * 10 + c - '0'; c = Getchar(); }return x * f; }#define maxn 3010 #define oo 2147483647int n, usr, m, head[maxn], nxt[maxn], to[maxn], dist[maxn], pay[maxn];void AddEdge(int a, int b, int c) {to[++m] = b; dist[m] = c; nxt[m] = head[a]; head[a] = m;return ; }int f[maxn][maxn], clea[maxn]; void dp(int u) {if(u > n - usr) {clea[u] = 1;f[u][0] = 0; f[u][1] = pay[u];return ;}f[u][0] = 0;for(int e = head[u]; e; e = nxt[e]) {dp(to[e]);for(int i = clea[u]; i >= 0; i--) if(f[u][i] < oo)for(int j = 0; j <= clea[to[e]]; j++) if(f[to[e]][j] < oo)f[u][i+j] = max(f[u][i+j], f[u][i] + f[to[e]][j] - (j ? dist[e] : 0));clea[u] += clea[to[e]];}return ; }int main() {n = read(); usr = read();for(int i = 1; i <= n - usr; i++) {int k = read();while(k--) {int u = read(), c = read();AddEdge(i, u, c);}}for(int i = n - usr + 1; i <= n; i++) pay[i] = read();for(int i = 1; i <= n; i++)for(int j = 0; j <= n; j++) f[i][j] = -oo;dp(1);for(int j = clea[1]; j; j--) if(f[1][j] >= 0) return printf("%d\n", j), 0;puts("0");return 0; }

?

轉載于:https://www.cnblogs.com/xiao-ju-ruo-xjr/p/7309030.html

總結

以上是生活随笔為你收集整理的[POJ1155]TELE的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 男女黄床上色视频免费的软件 | 亚洲专区av| 直接看的av | 日本色网址 | 又爽又黄又无遮挡 | 影音先锋男人站 | 怡红院成人影院 | 日本三级吃奶头添泬无码苍井空 | 国产精品国产三级国产专区52 | 中文字幕大全 | 日日夜夜精品视频免费 | 欧美三日本三级少妇三级99观看视频 | 欧美激情三级 | 97国产精品久久久 | 精品一区二区三区视频在线观看 | 久久久精品中文字幕 | 亚洲骚片| 都市豪门艳霸淫美妇 | 6080成人| 精品人妻天天爽夜夜爽视频 | 黄色片日韩 | 黄色1级视频 | 好看的中文字幕av | 青青草成人免费在线视频 | 手机av不卡 | 91国视频| 国产精品久久久久久一区二区三区 | 欧美人日b | av激情在线 | 国产清纯白嫩初高中在线观看性色 | 黄色网在线播放 | 国产成人99 | 日韩图色| 果冻传媒18禁免费视频 | 中文字幕一区二区av | 影音先锋在线看片资源 | 日韩伦理中文字幕 | 亚洲三区在线观看无套内射 | 人妻丝袜一区 | 麻豆视频在线免费看 | 亚洲综合少妇 | 姑娘第5集在线观看免费 | 亚洲国产一区二区在线观看 | 校园伸入裙底揉捏1v1h | 嫩草视频入口 | 久操视频在线播放 | √天堂 | 亚洲少妇网| 欧美sm视频 | 九九视频这里只有精品 | 菠萝菠萝蜜网站 | 久久福利免费视频 | 日韩精品一区二 | 好吊色一区二区 | 狼人综合av| 黑人一区二区三区四区五区 | 日本伊人网| 51吃瓜网今日吃瓜 | 亚洲乱码av | 天天舔天天爽 | 欧美日韩一区二区区别是什么 | 女人张开腿让男人桶爽 | 日韩一区二区免费播放 | 四虎免费看黄 | 国产精品一区久久 | 国产黄色高清视频 | 亚洲一区国产一区 | 亚洲第一黄色网 | 性猛交富婆╳xxx乱大交天津 | 欧美一级片免费观看 | 黄色av大全 | 久久国产精品久久久久久电车 | 免费在线观看视频 | 成人免费观看在线视频 | 久久精品无码一区二区三区毛片 | 中文字幕日本一区 | 成人午夜网 | 精品福利一区二区三区 | 男女污污网站 | 欧美深夜在线 | 国产成人免费网站 | 入禽太深免费视频 | 欧美一区二区三区系列电影 | 国产中文字幕乱人伦在线观看 | 美女污软件 | 一区二区视 | 五月香蕉网| 日本xxxxxxxxx| 国产黄色高清 | 黄色激情网址 | 精品播放 | 国产精品老女人 | 男生操男生网站 | 尤物193.com | 99这里只有精品 | 天堂av资源在线 | 少妇又紧又爽视频 | jizz处女| 日韩 国产 欧美 |