A8519 | Fibonacci Strings
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Fibonacci strings are defined as follows:
- $f_{1}$ = «a»
- $f_{2}$ = «b»
- $f_{n}$ = $f_{n-1} f_{n-2}$ , $n>2$
Thus, the first five Fibonacci strings are: "a", "b", "ba", "bab", "babba".
You are given a Fibonacci string and $m$ strings $s_{i}$ . For each string $s_{i}$ , find the number of times it occurs in the given Fibonacci string as a substring.
- $f_{1}$ = «a»
- $f_{2}$ = «b»
- $f_{n}$ = $f_{n-1} f_{n-2}$ , $n>2$
Thus, the first five Fibonacci strings are: "a", "b", "ba", "bab", "babba".
You are given a Fibonacci string and $m$ strings $s_{i}$ . For each string $s_{i}$ , find the number of times it occurs in the given Fibonacci string as a substring.
输入格式
The first line contains two space-separated integers $k$ and $m$ — the number of a Fibonacci string and the number of queries, correspondingly.
Next $m$ lines contain strings $s_{i}$ that correspond to the queries. It is guaranteed that strings $s_{i}$ aren't empty and consist only of characters "a" and "b".
The input limitations for getting 30 points are:
- $1<=k<=3000$
- $1<=m<=3000$
- The total length of strings $s_{i}$ doesn't exceed $3000$
The input limitations for getting 100 points are:
- $1<=k<=10^{18}$
- $1<=m<=10^{4}$
- The total length of strings $s_{i}$ doesn't exceed $10^{5}$
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.
Next $m$ lines contain strings $s_{i}$ that correspond to the queries. It is guaranteed that strings $s_{i}$ aren't empty and consist only of characters "a" and "b".
The input limitations for getting 30 points are:
- $1<=k<=3000$
- $1<=m<=3000$
- The total length of strings $s_{i}$ doesn't exceed $3000$
The input limitations for getting 100 points are:
- $1<=k<=10^{18}$
- $1<=m<=10^{4}$
- The total length of strings $s_{i}$ doesn't exceed $10^{5}$
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.
输出格式
For each string $s_{i}$ print the number of times it occurs in the given Fibonacci string as a substring. Since the numbers can be large enough, print them modulo $1000000007$ $(10^{9}+7)$ . Print the answers for the strings in the order in which they are given in the input.
输入输出样例
输入 #1
6 5 a b ab ba aba
输出 #1
3 5 3 3 1
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted