zoukankan      html  css  js  c++  java
  • 选课

    传送门:

    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <string>
    #include <cstdlib>
    using namespace std;
    #define ll long long
    #define re register
    inline void read(int &a)
    {
        a=0;
        int d=1;
        char ch;
        while(ch=getchar(),ch>'9'||ch<'0')
            if(ch=='-')
                d=-1;
        a=ch^48;
        while(ch=getchar(),ch>='0'&&ch<='9')
            a=(a<<3)+(a<<1)+(ch^48);
        a*=d;
    }
    struct note
    {
        int v,w,next;
    }edge[605];
    int head[605],num,f[305][305],m;
    inline void add(int u,int v,int w)
    {
        edge[++num].next=head[u];
        edge[num].v=v;
        edge[num].w=w;
        head[u]=num;
    }
    inline void dfs(int u,int fa)
    {
        for(re int i=head[u];i;i=edge[i].next)
        {
            if(edge[i].v!=fa)
            {
                dfs(edge[i].v,u);
                for(re int j=m;j>0;j--)
                    for(re int k=0;k<j;k++)
                        f[u][j]=max(f[u][j],f[u][j-k-1]+f[edge[i].v][k]+edge[i].w);
            }
        }
    }
    int main()
    {
        int n;
        read(n);
        read(m);
        for(re int i=1;i<=n;i++)
        {
            int u,w;
            read(u);
            read(w);
            add(u,i,w);
            add(i,u,w);
        }
        dfs(0,-1);
        printf("%d",f[0][m]);
        return 0;
    }
  • 相关阅读:
    idea--不能启动问题
    linux--mysql5.7安装
    vmware
    debezium
    java枚举
    springfox
    日志级别
    lombok--知识点
    es6--箭头函数
    网址访问过慢
  • 原文地址:https://www.cnblogs.com/acm1ruoji/p/10877773.html
Copyright © 2011-2022 走看看