您当前的位置: 首页 > 

先求一个导

暂无认证

  • 0浏览

    0关注

    291博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

牛客练习赛97 D(经典树形dp不会)

先求一个导 发布时间:2022-03-13 21:05:11 ,浏览量:0

题目 题意: 给定一棵n个点的树,有x种普通颜色,y种特殊颜色。现在要进行染色,普通颜色染色没有限制,特殊颜色染色时要求相邻两个节点不能染相同的特殊颜色。 思路: 树形dp. f[cur][0] = Π (xf[son][0] + yf[son][1]) f[cur][1] = Π (x*f[son][0] + (y-1)*f[son][1]) 时间复杂度: O(n) 代码:

// Problem: 月之暗面
// Contest: NowCoder
// URL: https://ac.nowcoder.com/acm/contest/30030/D
// Memory Limit: 524288 MB
// Time Limit: 4000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define OldTomato ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
#define fir(i,a,b) for(int i=a;iT;
   // read(T);
   while(T--)
   {
   	 solve();
   }
   return 0;
}

关注
打赏
1662037414
查看更多评论
立即登录/注册

微信扫码登录

0.0391s