CodeforcesRound#245(Div.2)D(树的性质+状压+dfs)_html/css_WEB-ITnose
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了CodeforcesRound#245(Div.2)D(树的性质+状压+dfs)_html/css_WEB-ITnose,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2090字,纯文字阅读大概需要3分钟。
内容图文
![CodeforcesRound#245(Div.2)D(树的性质+状压+dfs)_html/css_WEB-ITnose](/upload/InfoBanner/zyjiaocheng/400/659d8ea676a44436a45f1e7a8a460c41.jpg)
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Iahub and Iahubina went to a picnic in a forest full of trees. Less than 5 minutes passed before Iahub remembered of trees from programming. Moreover, he invented a new problem and Iahubina has to solve it, otherwise Iahub won't give her the food.
Iahub asks Iahubina: can you build a rooted tree, such that
Iahubina has to guess the tree. Being a smart girl, she realized that it's possible no tree can follow Iahub's restrictions. In this way, Iahub will eat all the food. You need to help Iahubina: determine if there's at least one tree following Iahub's restrictions. The required tree must contain n nodes.
Input
The first line of the input contains integer n (1?≤?n?≤?24). Next line contains n positive integers: the i-th number represents ci (1?≤?ci?≤?n).
Output
Output on the first line "YES" (without quotes) if there exist at least one tree following Iahub's restrictions, otherwise output "NO" (without quotes).
Sample test(s)
input
41 1 1 4
output
YES
input
51 1 5 2 1
output
NO
题意:RT
思路:首先注意,根据每个点至少有两个孩子这个性质可以知道,为1的点的数量一定会>=n/2
所以24个点的状态就减少为12个点的状态,敲好可以状压
只考虑不为1的点,先按降序排序,然后一个一个选孩子,如果已经轮到i来选孩子,先检查它自己有没有被前面的点选为孩子,
如果没有选,则不需要继续了,因为它不可能有父亲了
如果选了,则继续为i选2个或以上的孩子,选过的点标记一下就可以了
整个过程用递归算就可以了
内容总结
以上是互联网集市为您收集整理的CodeforcesRound#245(Div.2)D(树的性质+状压+dfs)_html/css_WEB-ITnose全部内容,希望文章能够帮你解决CodeforcesRound#245(Div.2)D(树的性质+状压+dfs)_html/css_WEB-ITnose所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。