CF176B.Word Cut

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Let's consider one interesting word game. In this game you should transform one word into another through special operations.

Let's say we have word w, let's split this word into two non-empty parts x and y so, that w = xy. A split operation is transforming word w = xy into word u = yx. For example, a split operation can transform word "wordcut" into word "cutword".

You are given two words start and end. Count in how many ways we can transform word start into word end, if we apply exactly k split operations consecutively to word start.

Two ways are considered different if the sequences of applied operations differ. Two operation sequences are different if exists such number i (1 ≤ i ≤ k), that in the i-th operation of the first sequence the word splits into parts x and y, in the i-th operation of the second sequence the word splits into parts a and b, and additionally x ≠ a holds.

我们来考虑一个有趣的单词游戏。在该游戏中,你需要通过特定的操作将一个单词变换为另一个单词。

假设我们有一个单词 ww,将其拆分为两个非空部分 xx 和 yy,使得 w=xyw = xy。所谓拆分操作,是指将单词 w=xyw = xy 变换为单词 u=yxu = yx。例如,对单词 “wordcut” 执行一次拆分操作可得到 “cutword”。

给定两个单词 start\text{start} 和 end\text{end}。请计算:对单词 start\text{start} 连续执行恰好 kk 次拆分操作,使其变为 end\text{end} 的方案数。

若两种方案所应用的操作序列不同,则视为不同方案。两个操作序列不同,当且仅当存在某个序号 ii(1≤i≤k1 \le i \le k),使得在第一个序列的第 ii 次操作中,单词被拆分为 xx 和 yy;而在第二个序列的第 ii 次操作中,单词被拆分为 aa 和 bb,且满足 x≠ax \ne a。

输入格式

The first line contains a non-empty word start, the second line contains a non-empty word end. The words consist of lowercase Latin letters. The number of letters in word start equals the number of letters in word end and is at least 2 and doesn't exceed 1000 letters.

The third line contains integer k (0 ≤ k ≤ 105) — the required number of operations.

第一行包含一个非空单词 start,第二行包含一个非空单词 end。这些单词均由小写拉丁字母组成。单词 start 的字母数等于单词 end 的字母数,且该长度至少为 2,至多为 1000。

第三行包含一个整数 k(0 ≤ k ≤ 10⁵)—— 所需的操作次数。

输出格式

Print a single number — the answer to the problem. As this number can be rather large, print it modulo 1000000007 (109 + 7).

输出一个整数——即该问题的答案。由于该数可能非常大,请输出它对 10000000071000000007(即 109+710^9 + 7)取模的结果。

输入输出样例

  • 输入#1

    ab
    ab
    2

    输出#1

    1
  • 输入#2

    ababab
    ababab
    1

    输出#2

    2
  • 输入#3

    ab
    ba
    2

    输出#3

    0

说明/提示

The sought way in the first sample is:

ab  →  a|b  →  ba  →  b|a  →  ab

In the second sample the two sought ways are:

  • ababab  →  abab|ab  →  ababab
  • ababab  →  ab|abab  →  ababab

第一个样例中所求的路径为:

ab  →  a|b  →  ba  →  b|a  →  ab

第二个样例中所求的两条路径为:

  • ababab  →  abab|ab  →  ababab
  • ababab  →  ab|abab  →  ababab

输入解题思路,AI测评打分。不知道怎么写?

首页