当前位置:网站首页>CF1481F AB Tree
CF1481F AB Tree
2022-06-21 21:52:00 【doctorZ_】
The main idea of the topic
Given a tree n n n Tree of nodes , Root is 1 1 1 , Each node is assigned a character a or b.
Require characters in the whole tree a The quantity of is x x x , character b The quantity of is n − x n-x n−x .
Define the node v v v String on :
- if v v v Root node , be v v v The string on is the character assigned to the root node .
- otherwise , v v v The string on is the end of the string on the parent node plus v v v Characters assigned to .
Please assign characters to each node , After meeting the characters a ,b Quantity requirements , Minimize the types of strings on all nodes .
solution
Fairy structure
Let the maximum depth be d d d, It is easy to find that the lower bound of the answer must be d d d, As long as each layer is dyed with one color , Let's analyze the upper bound again , Based on hand play and guessing , It can be found that the upper bound should be d + 1 d+1 d+1 Of , Consider that the answer is d + 1 d+1 d+1 What should be the situation , First, make sure that the color of non leaf nodes in the same layer must be the same , And only the color of some leaf nodes in one layer is different from that of non leaf nodes , Because non leaf nodes have at least one son , So the number of non leaf nodes in a layer must be ≤ ⌊ m 2 ⌋ \le \lfloor\frac{m}{2}\rfloor ≤⌊2m⌋ Of ( m m m Denotes the number of undyed knots remaining ), That is to say, there must be a way to make the non leaf nodes of each layer the same , Then the leaf nodes should be dyed to the same color as the non leaf nodes , If it's not enough, dye it and paint something else
It is not difficult to find that at most one layer of leaves is different in color , So the upper bound of the answer is n + 1 n+1 n+1
The rest can be judged by the backpack , The maximum number of different stratification points is O ( n ) O(\sqrt n) O(n) Kind of , Direct binary optimization of multiple knapsacks , Time complexity O ( n ) O(\sqrt n) O(n)
Code mo de
边栏推荐
- Ln2220 2A overcurrent 5v1a High Efficiency Boost IC chip dc/dc voltage regulator
- 提升四大性能!D-Wave发布下一代量子退火机原型
- Build Eureka server cluster
- 杰理之配对成对耳后,想保持两个耳机都输出立体声【篇】
- Go language unit test simulates service request and interface return
- Fm5012d small fan integrated IC scheme
- Jerry's acquisition of current audio file (long) file name and current (long) folder name [chapter]
- 怎样有效率地进行外文文献检索?
- js中的for.....in函数
- What are the authoritative websites that search English documents like CNKI?
猜你喜欢

Build Eureka server cluster

潮流媒體Hypebeast擬曲線上市:作價5.3億美元 擬第三季完成

Mendeley 安装、配置、使用

六个拿来就能用的有趣网页特效

What is EGFP, green fluorescent protein
![When Jerry made Bluetooth transmission, when he modified stereo to mono differential output, there was a jam sound at the receiving end [chapter]](/img/ef/35a74fe3b1a8035afb6c50e6880860.png)
When Jerry made Bluetooth transmission, when he modified stereo to mono differential output, there was a jam sound at the receiving end [chapter]

matplotlib plt. Details of subplots()

Huawei Hongmeng development lesson 3

How to write a proposal for an English paper?

Yx2811 landscape installation driver IC
随机推荐
LeetCode508-出现次数最多的子树元素和-深搜
ARP protocol and ARP attack
英文论文要怎么查重?
CF1481F AB Tree
Why does defer not execute after the program exits
solidity实现智能合约教程(4)-ERC1155合约
杰理之外挂收音注意事项【篇】
[yolov5] opencv450 loads onnx for reasoning GPU acceleration
杰理之开启四声道打开 EQ 后播歌卡顿问题【篇】
英文论文如何进行润色?
12. signal foundation
Eureka控制台访问微服务暴露的info端点
Xcode plug-in management tool Alcatraz
Phpmailer sends mails through SMTP. Some of the same sending contents succeed and some fail
js的对象操作(与c的对象比较简单的多)
哪些ipad的APP可以很好的阅读英文文献?
Go语言单元测试模拟服务请求和接口返回
Jerizhi, processing method for prompting chip information mismatch and error code 10 [chapter]
华为鸿蒙开发第三课
Tc3608h high efficiency 1.2MHz DC-DC booster IC