当前位置:网站首页>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
边栏推荐
- 六个拿来就能用的有趣网页特效
- K - Clairewd’s message HDU - 4300 (EXKMP)
- Merge two ordered arrays
- Jerry's SD card reuse IIC precautions [chapter]
- Fs9935 high efficiency constant current limiting WLED drive IC
- Go语言单元测试基础从入门到放弃
- Summary of intelligence problems
- 杰理之获取当前音频文件(长)文件名和当前(长)文件夹名【篇】
- matplotlib plt. Details of subplots()
- ACM. HJ51 输出单向链表中倒数第k个结点 ●
猜你喜欢

Cocoapods installation (after xcode8.0, the infinite card is in the setting up cocoapods master repo)

ACM. Hj35 serpentine matrix ●

InteliJ-IDEA-高效技巧(一)

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

Introduction to security encryption

Definition of unused processing methods when compiling C51 with keil 5

你真的了解二叉树吗?(上篇)

盐语Saltalk获800万美元A轮融资:继续扩大团队及市场覆盖
![Time modification method for search device of Jerry's Bluetooth transmitter [chapter]](/img/ac/5a1d8cabbc61b24d451753e2f5c8dd.png)
Time modification method for search device of Jerry's Bluetooth transmitter [chapter]

晶合集成通过注册:拟募资95亿 合肥建投与美的是股东
随机推荐
How to write a proposal for an English paper?
solidity实现智能合约教程(4)-ERC1155合约
For in JS In function
AWS CloudWatch
Cocoapods installation (after xcode8.0, the infinite card is in the setting up cocoapods master repo)
Mendeley installation, configuration and use
一文彻底搞懂MySQL基础:B树和B+树的区别
JS里的数据类型(基础)
With what to save you? My attention
VLAN division based on interface: static VLAN [not perfect]
Which small directions of cv/nlp are easy to publish papers?
MySQL创建表时的条件有哪些
Jerizhi, processing method for prompting chip information mismatch and error code 10 [chapter]
When Jerry made Bluetooth transmission, when he modified stereo to mono differential output, there was a jam sound at the receiving end [chapter]
撰写学术论文引用文献时,标准的格式是怎样的?
Go language self-study series | golang standard library encoding/xml
Scientific research cartoon | you can learn EEG by looking at the picture. Would you like to try it?
InteliJ-IDEA-高效技巧(一)
Tc3608h high efficiency 1.2MHz DC-DC booster IC
What kind of person are you in life?