搜索

Codeforces Round #245 (Div. 2)D(树的性质+状压+dfs)_html/css_WEB-ITnose

php中文网
发布: 2016-06-24 11:52:42
原创
1573人浏览过

E. Guess the Tree

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

  • each internal node (a node with at least one son) has at least two sons;
  • node i has ci nodes in its subtree?
  • 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).

    DALL·E 2
    DALL·E 2

    OpenAI基于GPT-3模型开发的AI绘图生成工具,可以根据自然语言的描述创建逼真的图像和艺术。

    DALL·E 244
    查看详情 DALL·E 2

    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个或以上的孩子,选过的点标记一下就可以了


               整个过程用递归算就可以了


    HTML速学教程(入门课程)
    HTML速学教程(入门课程)

    HTML怎么学习?HTML怎么入门?HTML在哪学?HTML怎么学才快?不用担心,这里为大家提供了HTML速学教程(入门课程),有需要的小伙伴保存下载就能学习啦!

    下载
    来源:php中文网
    本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
    最新问题
    开源免费商场系统广告
    热门教程
    更多>
    最新下载
    更多>
    网站特效
    网站源码
    网站素材
    前端模板
    关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
    php中文网:公益在线php培训,帮助PHP学习者快速成长!
    关注服务号 技术交流群
    PHP中文网订阅号
    每天精选资源文章推送
    PHP中文网APP
    随时随地碎片化学习
    PHP中文网抖音号
    发现有趣的

    Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号