A15330 | Fibonacci Strings
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
In all schools in Buryatia, in the $1$ class, everyone is told the theory of Fibonacci strings.
"A block is a subsegment of a string where all the letters are the same and are bounded on the left and right by the ends of the string or by letters other than the letters in the block. A string is called a Fibonacci string if, when it is divided into blocks, their lengths in the order they appear in the string form the Fibonacci sequence ( $f_0 = f_1 = 1$ , $f_i = f_{i-2} + f_{i-1}$ ), starting from the zeroth member of this sequence. A string is called semi-Fibonacci if it possible to reorder its letters to get a Fibonacci string."
Burenka decided to enter the Buryat State University, but at the entrance exam she was given a difficult task. She was given a string consisting of the letters of the Buryat alphabet (which contains exactly $k$ letters), and was asked if the given string is semi-Fibonacci. The string can be very long, so instead of the string, she was given the number of appearances of each letter ( $c_i$ for the $i$ -th letter) in that string. Unfortunately, Burenka no longer remembers the theory of Fibonacci strings, so without your help she will not pass the exam.
"A block is a subsegment of a string where all the letters are the same and are bounded on the left and right by the ends of the string or by letters other than the letters in the block. A string is called a Fibonacci string if, when it is divided into blocks, their lengths in the order they appear in the string form the Fibonacci sequence ( $f_0 = f_1 = 1$ , $f_i = f_{i-2} + f_{i-1}$ ), starting from the zeroth member of this sequence. A string is called semi-Fibonacci if it possible to reorder its letters to get a Fibonacci string."
Burenka decided to enter the Buryat State University, but at the entrance exam she was given a difficult task. She was given a string consisting of the letters of the Buryat alphabet (which contains exactly $k$ letters), and was asked if the given string is semi-Fibonacci. The string can be very long, so instead of the string, she was given the number of appearances of each letter ( $c_i$ for the $i$ -th letter) in that string. Unfortunately, Burenka no longer remembers the theory of Fibonacci strings, so without your help she will not pass the exam.
输入格式
The first line contains one integer $t$ ( $1 \leq t \leq 10^4$ ) — the number of test cases. The following is a description of the input data sets.
The first line of each test case contains one integer $k$ ( $1 \leq k \leq 100$ ) — the number of letters in the alphabet.
The second line of each test case contains $k$ integers $c_1, c_2, \ldots, c_k$ ( $1 \leq c_i \leq 10^9$ ) — the number of occurrences of each letter in the string.
The first line of each test case contains one integer $k$ ( $1 \leq k \leq 100$ ) — the number of letters in the alphabet.
The second line of each test case contains $k$ integers $c_1, c_2, \ldots, c_k$ ( $1 \leq c_i \leq 10^9$ ) — the number of occurrences of each letter in the string.
输出格式
For each test case print the string "YES" if the corresponding string is semi-Fibonacci, and "NO" if it is not.
You can print "YES" and "NO" in any case (for example, the strings "yEs", "yes", "Yes" will be recognized as a positive answer).
You can print "YES" and "NO" in any case (for example, the strings "yEs", "yes", "Yes" will be recognized as a positive answer).
输入输出样例
输入 #1
6 1 1 2 1 1 2 1 2 3 3 1 3 2 7 5 6 26 8 3 4 13 34
输出 #1
YES YES NO YES NO YES
In the first test case, a one-character string is semi-Fibonacci, being itself a Fibonacci string.
In the second test case, a string of two different characters is Fibonacci.
In the third test case, the string "abb" (let the first of the alphabet letter be a, the second letter b) is not a semi-Fibonacci string, since no permutation of its letters ("abb", "bab", and "bba") is a Fibonacci string.
In the fourth test case, two permutations of the letters of the string "abaccac" (the first letter is a, the second letter is b, the third letter is c) are Fibonacci strings — "abaaccc" and "cbccaaa".
In the second test case, a string of two different characters is Fibonacci.
In the third test case, the string "abb" (let the first of the alphabet letter be a, the second letter b) is not a semi-Fibonacci string, since no permutation of its letters ("abb", "bab", and "bba") is a Fibonacci string.
In the fourth test case, two permutations of the letters of the string "abaccac" (the first letter is a, the second letter is b, the third letter is c) are Fibonacci strings — "abaaccc" and "cbccaaa".
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted