您当前的位置: 首页 > 

钟钟终

暂无认证

  • 2浏览

    0关注

    233博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

2/20 树上dp+正方形个数问题(dp)+dfs+连通块+背包

钟钟终 发布时间:2022-02-20 20:24:18 ,浏览量:2

P1352 没有上司的舞会 https://www.luogu.com.cn/problem/P1352

#include 

using namespace std;
const int maxn=1e6+5;
struct node
{
    int  to,nxt;
}e[maxn];
int n,r[maxn],f[maxn][4],head[maxn],cnt,in[maxn];
void add(int from,int to)
{
    e[++cnt].to=to;
    e[cnt].nxt=head[from];
    head[from]=cnt;
}
void dfs(int u)
{
    for(int i=head[u];i;i=e[i].nxt)
    {
        int v=e[i].to;
        dfs(v);
        f[u][0]+=max(f[v][0],f[v][1]);
        f[u][1]+=f[v][0];
    }
    f[u][1]+=r[u];
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i            
关注
打赏
1664378814
查看更多评论
0.0383s