CF429C.Guess the Tree
提高+/省选-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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 c__i 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.
伊阿胡布和伊阿胡比娜去了一片长满树木的森林野餐。不到5分钟,伊阿胡布就想起了编程中的树结构。不仅如此,他还自创了一个新问题,伊阿胡比娜必须解答出来,否则伊阿胡布就不给她食物。
伊阿胡布问伊阿胡比娜:你能否构造一棵有根树,使得
- 每个内部节点(即至少有一个子节点的节点)至少有两个子节点;
- 节点 i 的子树中恰好包含 ci 个节点?
伊阿胡比娜需要猜出这棵树。作为一个聪明的女孩,她意识到可能根本不存在满足伊阿胡布限制条件的树。这样一来,伊阿胡布就会独享所有食物。你需要帮助伊阿胡比娜:判断是否存在至少一棵满足伊阿胡布限制条件的树。所要求的树必须恰好包含 n 个节点。
输入格式
The first line of the input contains integer n (1 ≤ n ≤ 24). Next line contains n positive integers: the i-th number represents c__i (1 ≤ c__i ≤ n).
输入的第一行包含一个整数 n(1 ≤ n ≤ 24)。下一行包含 n 个正整数:第 i 个数表示 ci(1 ≤ ci ≤ n)。
输出格式
Output on the first line "YES" (without quotes) if there exist at least one tree following Iahub's restrictions, otherwise output "NO" (without quotes).
如果存在至少一棵满足伊胡布限制条件的树,则在第一行输出 “YES”(不带引号);否则输出 “NO”(不带引号)。
输入输出样例
输入#1
4 1 1 1 4
输出#1
YES
输入#2
5 1 1 5 2 1
输出#2
NO
输入解题思路,AI测评打分。不知道怎么写?