CF177G2.Fibonacci Strings

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Fibonacci strings are defined as follows:

  • f1f_{1} = «a»
  • f2f_{2} = «b»
  • fnf_{n} = fn1 fn2f_{n-1} f_{n-2} , n>2n>2

Thus, the first five Fibonacci strings are: "a", "b", "ba", "bab", "babba".

You are given a Fibonacci string and mm strings sis_{i} . For each string sis_{i} , find the number of times it occurs in the given Fibonacci string as a substring.

输入格式

The first line contains two space-separated integers kk and mm — the number of a Fibonacci string and the number of queries, correspondingly.

Next mm lines contain strings sis_{i} that correspond to the queries. It is guaranteed that strings sis_{i} aren't empty and consist only of characters "a" and "b".

The input limitations for getting 30 points are:

  • 1<=k<=30001<=k<=3000
  • 1<=m<=30001<=m<=3000
  • The total length of strings sis_{i} doesn't exceed 30003000

The input limitations for getting 100 points are:

  • 1<=k<=10181<=k<=10^{18}
  • 1<=m<=1041<=m<=10^{4}
  • The total length of strings sis_{i} doesn't exceed 10510^{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 sis_{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 10000000071000000007 (109+7)(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
    
首页