#include#include#include#include#include#include#include#include#include

黄色网页视频 I 影音先锋日日狠狠久久 I 秋霞午夜毛片 I 秋霞一二三区 I 国产成人片无码视频 I 国产 精品 自在自线 I av免费观看网站 I 日本精品久久久久中文字幕5 I 91看视频 I 看全色黄大色黄女片18 I 精品不卡一区 I 亚洲最新精品 I 欧美 激情 在线 I 人妻少妇精品久久 I 国产99视频精品免费专区 I 欧美影院 I 欧美精品在欧美一区二区少妇 I av大片网站 I 国产精品黄色片 I 888久久 I 狠狠干最新 I 看看黄色一级片 I 黄色精品久久 I 三级av在线 I 69色综合 I 国产日韩欧美91 I 亚洲精品偷拍 I 激情小说亚洲图片 I 久久国产视频精品 I 国产综合精品一区二区三区 I 色婷婷国产 I 最新成人av在线 I 国产私拍精品 I 日韩成人影音 I 日日夜夜天天综合

zoj 2315 New Year Bonus Grant

系統(tǒng) 2069 0

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1315

簡單的樹型DP ??

代碼:

      #include<iostream>

#include<cstdio>

#include<cstring>

#include<string>

#include<algorithm>

#include<cmath>

#include<map>

#include<set>

#include<vector>

#include<stack>

#include<queue>

#pragma comment(linker, "/STACK:1024000000,1024000000")

#define ll long long



using namespace std;

const int INF=0x3f3f3f3f;

const int MOD=100000007;

const int N=500005;

int MAX[N][2],f[N];

int in[N],c[N];

int head[N],I;

vector<int>vt;

struct node

{

    int j,next;

}edge[N];

void add(int i,int j)

{

    edge[I].j=j;

    edge[I].next=head[i];

    head[i]=I++;

}

int dp(int x,int k)

{

    if(MAX[x][k]!=-1)

    return MAX[x][k];

    if(in[x]==0)

    return (MAX[x][k]=0);

    MAX[x][k]=0;

    int tmp=-INF,l=0;

    for(int t=head[x];t!=-1;t=edge[t].next)

    {

        int w=edge[t].j;

        MAX[x][k]+=(dp(w,0));

        if(dp(w,1)-dp(w,0)>tmp)

        {

            tmp=dp(w,1)-dp(w,0);

            l=w;

        }

    }

    if(k==0)

    {

        c[x]=l;

        MAX[x][k]+=(tmp+1);

    }

    return MAX[x][k];

}

void dfs(int x,int k)

{//cout<<x<<" "<<k<<endl;

    if(in[x]==0) return;

    if(k==0)

    vt.push_back(c[x]);

    for(int t=head[x];t!=-1;t=edge[t].next)

    {

        int w=edge[t].j;

        if(k==0&&c[x]==w)

        dfs(w,1);

        else

        dfs(w,0);

    }

}

int main()

{

    //freopen("data.in","r",stdin);

    int T;

    cin>>T;

    while(T--)

    {

        int n;

        cin>>n;

        memset(in,0,sizeof(in));

        memset(head,-1,sizeof(head));I=0;

        for(int i=2;i<=n;++i)

        {cin>>f[i];++in[f[i]];add(f[i],i);}

        memset(MAX,-1,sizeof(MAX));

        cout<<(dp(1,0)*1000)<<endl;

        vt.clear();

        dfs(1,0);

        sort(vt.begin(),vt.end());

        for(unsigned int i=0;i<vt.size();++i)

        {

            if(i>0) cout<<" ";

            cout<<vt[i];

        }cout<<endl;

    }

    return 0;

}


    

zoj 2315 New Year Bonus Grant


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯(lián)系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長非常感激您!手機(jī)微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦?。?!

發(fā)表我的評論
最新評論 總共0條評論