欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

Anniversaryparty樹形dp-創(chuàng)新互聯(lián)

簡(jiǎn)單的樹形dpAnniversaryparty
樹形dp

dp[i] 表示以i為根的包括i 的大歡樂度

專業(yè)從事成都網(wǎng)站建設(shè)、做網(wǎng)站,高端網(wǎng)站制作設(shè)計(jì),微信小程序,網(wǎng)站推廣的成都做網(wǎng)站的公司。優(yōu)秀技術(shù)團(tuán)隊(duì)竭力真誠服務(wù),采用H5頁面制作+CSS3前端渲染技術(shù),響應(yīng)式網(wǎng)站設(shè)計(jì),讓網(wǎng)站在手機(jī)、平板、PC、微信下都能呈現(xiàn)。建站過程建立專項(xiàng)小組,與您實(shí)時(shí)在線互動(dòng),隨時(shí)提供解決方案,暢聊想法和感受。

f[i] 表示以i為根不包括i 的大歡樂度

葉節(jié)點(diǎn)則為 f[i] = 0, dp[i] = w[i]  只要初始化 dp f 都全為0 就可以了 dfs會(huì)自動(dòng)復(fù)制

說實(shí)話我覺得這題很不嚴(yán)謹(jǐn) 他說歡樂度可以為負(fù)值  按理來說如果小于0 就應(yīng)該將歡樂度設(shè)為0 表示那個(gè)人不參加

最后是 無論設(shè)不設(shè)為0 都AC 證明根本沒有歡樂度為負(fù)值的

要注意的是

1. 不是只有一個(gè)case  我一開始以為只有一個(gè)case  一直錯(cuò) 要處理到?jīng)]有輸入為止。。。 題目又沒說明

2. 有可能有多棵樹 所以要多次dfs()

View Code
Anniversary party

Time Limit :2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) :5   Accepted Submission(s) : 2
Font: Times New Roman| Verdana | Georgia
Font Size: ← →
Problem Description
Thereis going to be a party to celebrate the 80-th Anniversary of the Ural State University. The University has a hierarchical structure of employees. It means that the supervisor relation forms a tree rooted at the rector V. E. Tretyakov. In order to make the party funny for every one, the rector does not want both an employee and his or her immediate supervisor to be present. The personnel office has evaluated conviviality of each employee, so everyone has some number (rating) attached to him or her. Your task is to make a list of guests with the maximal possible sum of guests' conviviality ratings.Input
Employees are numberedfrom 1 to N. A first line of input contains a number N. 1 <= N <= 6 000. Each of the subsequent N lines contains the conviviality rating of the corresponding employee. Conviviality rating is an integer number in a range from -128 to 127. After that go T lines that describe a supervisor relation tree. Each line of the tree specification has the form: 
L K 
It means that the K-th employee is an immediate supervisor of the L-th employee. Input is ended with the line 
0 0
Output
Output should contain the maximal sum of guests' ratings.Sample Input
711111111 32 36 47 44 53 50 0
Sample Output
5
View Code
#include <stdio.h>
#include<algorithm>
#include<string.h>

const int MAXN = 6005;
struct node
{
int index ;
    node*next ;
}adj[MAXN];
bool vis[MAXN], isRoot[MAXN];
int n, m, f[MAXN], dp[MAXN], w[MAXN]; 
void addEdge(int x, int y)
{
    node*p = new node;
    p->index = y;
    p->next = adj[x].next;
    adj[x].next= p;
    isRoot[y]= 0;
}
int max(int a, int b)
{return a>=b ?a :b  ;  }
void dfs(int root)
{
    vis[root]= 1;
    node*p = adj[root].next;
while( p != NULL )
    {
int u = p->index;
if(!vis[u])
        {
            dfs(u);
//    dp[root] += f[u]<0 ?0 :f[u];
//    int tmp = max(dp[u], f[u]);
//    f[root] += tmp < 0 ? 0 : tmp ;            dp[root] += f[u];
            f[root]+= max(dp[u], f[u]);
        }
        p= p->next;
    }
    dp[root]+= w[root];
}
int main()
{
int i, a, b, root, ans = 0;
while(scanf("%d", &n)!=EOF)
    {
        ans= 0;
for(i=1; i<=n; i++)
        {
            scanf("%d", &w[i]);
            isRoot[i]= 1; dp[i] = f[i] = 0;
            adj[i].next= NULL, vis[i] = 0;
        }
while(scanf("%d %d", &a, &b), a|b)
            addEdge(b, a);
for(i=1; i<=n; i++)
if(isRoot[i])
            {
                dfs(i);
                ans+= max(dp[i], f[i]);
            }
            printf("%d
", ans);
    }
return 0;
}

當(dāng)前題目:Anniversaryparty樹形dp-創(chuàng)新互聯(lián)
轉(zhuǎn)載源于:http://chinadenli.net/article20/djjgco.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站制作標(biāo)簽優(yōu)化、網(wǎng)站制作、企業(yè)網(wǎng)站制作外貿(mào)網(wǎng)站建設(shè)、網(wǎng)站內(nèi)鏈

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

成都定制網(wǎng)站網(wǎng)頁設(shè)計(jì)
少妇特黄av一区二区三区| 久久本道综合色狠狠五月| 91天堂免费在线观看| 精品人妻少妇二区三区| 日韩成人动作片在线观看| 久草热视频这里只有精品| 91人妻人人揉人人澡人| 日韩精品小视频在线观看| 亚洲国产色婷婷久久精品| 成人日韩在线播放视频| 国产在线成人免费高清观看av| 亚洲国产成人久久一区二区三区| 97人妻精品一区二区三区男同| 午夜福利视频六七十路熟女| 欧美成人免费视频午夜色| 日本黄色美女日本黄色| 亚洲一区二区三在线播放| 日本在线视频播放91| 欧美日韩综合综合久久久| 日韩精品一区二区毛片| 天堂热东京热男人天堂| 欧美老太太性生活大片| 欧美乱妇日本乱码特黄大片| 欧美整片精品日韩综合| 丰满人妻熟妇乱又乱精品古代| 99热九九热这里只有精品| 国产老熟女乱子人伦视频| 中文字幕日产乱码一区二区| 国产av一区二区三区久久不卡| 91老熟妇嗷嗷叫太91| 91日韩欧美在线视频| 日韩日韩欧美国产精品| 日韩在线视频精品视频| 久久一区内射污污内射亚洲| 日本欧美三级中文字幕| 国产av一区二区三区四区五区| 久久亚洲国产视频三级黄| 欧美夫妻性生活一区二区| 亚洲中文在线中文字幕91| 精品国产亚洲免费91| 激情五月激情婷婷丁香|